예시용 Series

fruit = Series([2500,3800,1200,6000], index=['apple','banana','peer','cherry'])     # 시리즈 객체 생성
fruit

출력>
apple     2500
banana    3800
peer      1200
cherry    6000
dtype: int64

 

Pandas Series로 아래 두 가지를 진행해봅시다. 

 

(1) 값 or 인덱스만 뽑기

(2) Series에 이름 붙이기


(1)값 or 인덱스만 뽑기

print(fruit.values)           # 값만 뽑기
print(fruit.index)            # 인덱스만 뽑기

출력>
[2500 3800 1200 6000]
Index(['apple', 'banana', 'peer', 'cherry'], dtype='object')

 

(2)Series에 이름 붙이기

fruit.name = 'fruitPrice'
fruit.index.name = 'fruitName'            # clumm의 이름 = 색인
print(fruit)

출력>
fruitName
apple     2500
banana    3800
peer      1200
cherry    6000
Name: fruitPrice, dtype: int64

'python > [modules] Pandas' 카테고리의 다른 글

6. 데이터의 기본연산  (0) 2023.04.26
5. DataFrame을 다뤄보자  (0) 2023.04.26
4. DataFrame 객체를 만들기  (0) 2023.04.26
2. pandas를 임포트 하고 Series를 만들어보자  (0) 2023.04.26
1. pandas란?  (0) 2023.04.26

+ Recent posts