빅데이터 분석기사[python]/pandas와 기본 데이터 처리
[python 파이썬, pandas 판다스] series와 dataframe
sunning
2022. 5. 9. 22:44
728x90
반응형
판다스(pandas)
- 자료구조 및 데이터 분석 처리를 위한 파이썬의 핵심 패키지
- 판다스는 시리즈(Series)와 데이터프레임(DataFrame) 형태 두 가지로 나눌 수 있음
시리즈(series)
- index와 value의 형태를 갖고 있는 판다스의 자료 구조
- value 말고 index를 갖는다는 점에서 리스트와 차이점이 있음
import pandas as pd
from pandas import Series, DataFrame
### Series ###
a = Series([4,6,8,10])
print(a)
print(a.values) ## value
print(a.index)
## 시리즈 인덱스 변경하기
a2 = Series([4,6,8,10], index = ['a','b','c','d'])
print(a2)
0 4 1 6 2 8 3 10 dtype: int64 [ 4 6 8 10] RangeIndex(start=0, stop=4, step=1) a 4 b 6 c 8 d 10 dtype: int64 |
데이터프레임(DataFrame)
- 2차원 행렬구조로 구성된 판다스의 핵심 자료유형
- DataFrame은 여러 개의 Series로 이루어져 있음
### DataFrame ###
s1 = Series(['a1','b1','c1','d1'], index = ['a','b','c','d'])
s2 = Series(['a2','b2','c2','d2'], index = ['a','b','c','d'])
s3 = Series(['a3','b3','c3','d3'], index = ['a','b','c','d'])
c = DataFrame([s1, s2, s3])
c
728x90
반응형