import pandas as pd
# 시리즈 만들기
s = pd.Series(['banana', 42])
print(s)
# 인덱스 지정
s = pd.Series(['Wes McKinney', 'Creator of Pandas'], index=['Person', 'Who'])
print(s)
# 데이터 프레임 만들기
scientists = pd.DataFrame({
'Name' : ['Rosaline Franklin', 'William Gosset'],
'Occupation' : ['Chemist', 'Statistician'],
'Born' : ['1920-07-25', '1876-06-13'],
'Died' : ['1958-04-16', '1937-10-16'],
'Age' : [37, 61]}
)
print(scientists)
# index 별도 지정
scientists = pd.DataFrame(
data = {'Occupation' : ['Chemist', 'Statistician'],
'Born' : ['1920-07-25', '1876-06-13'],
'Died' : ['1958-04-16', '1937-10-16'],
'Age' : [37, 61]},
index = ['Rosaline Franklin', 'William Gosset'],
columns = ['Occupation', 'Born', 'Age', 'Died']
)
print(scientists)
# 순서보장
from collections import OrderedDict
scientists = pd.DataFrame(OrderedDict([
('Name' , ['Rosaline Franklin', 'William Gosset']),
('Occupation' , ['Chemist', 'Statistician']),
('Born' , ['1920-07-25', '1876-06-13']),
('Died' , ['1958-04-16', '1937-10-16']),
('Age' , [37, 61])
])
)
print(scientists)
# Series
first_row = scientists.loc['William Gosset']
print(type(first_row))
print(first_row.index)
print(first_row.values)
print(first_row.keys())
print(first_row.index[0])
print(first_row.keys()[0])
# 통계
ages = scientists['Age']
print(ages)
print(ages.mean())
print(ages.min())
print(ages.max())
print(ages.std())