import pandas
를 통해서 진행
import pandas as pd
s = pd.Series([1,4,9,16,25]) s
0 1 1 4 2 9 3 16 4 25 dtype: int64
t = pd.Series({'one' : 1, 'two' : 2, 'three' : 3, 'four' : 4, 'five' : 5}) t
one 1 two 2 three 3 four 4 five 5 dtype: int64
print(s[1]) print(t[1]) print(t[1:3])
4 2 two 2 three 3 dtype: int64
s [ s > s.median()] #자신의 중앙값보다 큰 값들만을 반환
3 16 4 25 dtype: int64
s[[3,1,4]]
3 16 1 4 4 25 dtype: int64
import numpy as np np.exp(s)
0 2.718282e+00 1 5.459815e+01 2 8.103084e+03 3 8.886111e+06 4 7.200490e+10 dtype: float64
s.dtype
dtype('int64')
t['one']
1
#Series에 값 추가 t['six'] = 6 t
one 1 two 2 three 3 four 4 five 5 six 6 dtype: int64
'six' in t
True
name
속성을 가지고 있다.Series
를 만들 때 이름을 붙일 수 있다.s = pd.Series(np.random.randn(5),name = "random_nums") s
0 -1.292386 1 -1.520983 2 -0.100095 3 2.486495 4 1.001782 Name: random_nums, dtype: float64
s.name = "임의의 난수" s
0 -1.292386 1 -1.520983 2 -0.100095 3 2.486495 4 1.001782 Name: 임의의 남수, dtype: float64