공부/Python
[Pandas] Series Data 다루기
잠수함토끼
2018. 12. 23. 16:14
mean(), min(), max(), std()
import pandas as pd
from collections import OrderedDict
s = pd.DataFrame({ 'Address':['Seoul','Asan'],
'occupation':['doctor','IT'],
'Born':['1981-01-10','1999-11-02'],
'Died':['2100-01-10','2099-01-02'],
'Age':[40,20]},
index=['a','b'],
columns=['occupation', 'Born', 'Died','Age'])
ages =s['Age']
print(ages) # 선택값 출력
print(type(ages)) # Series, 1개 열
print(ages.mean()) # 평균값
print(ages.min()) # 가장 작은 값
print(ages.max()) # 가장 큰 값
print(ages.std()) #
output
>>> print(ages) # 선택값 출력
a 40
b 20
Name: Age, dtype: int64
>>>
>>> print(type(ages)) # Series, 1개 열
<class 'pandas.core.series.Series'>
>>>
>>> print(ages.mean()) # 평균값
30.0
>>>
>>> print(ages.min())
20
>>>
>>> print(ages.max())
40
>>>
>>> print(ages.std())
14.1421356237
Series 함수
시리즈 Method | Comment | Sample |
---|---|---|
append | 2개 이상 시리즈 연결 | |
describe | 오약 통계 계산 | print(ages.describe()) |
drop_duplicates | 중복값 없는 시리즈 반환 | |
equals | 해당 값이 존재하는지 확인 | |
isin | 포함되어 있나? | print(ages.isin([20,30])) # a: False, b:True |
get_values | 값 구하기(values 속성 동일) | |
min | ages.min() | |
max | ages.max() | |
mean | 산술 평균 | ages.mean() |
median | 중간값 | |
replace | 값 고치기 | |
sample | 시리즈에서 임의 값 retrun | |
sort_values | value 정렬 | |
to_frame | Series To DataFrame |