pandas 기본 문법
from pandas import Series
data = [100, 200, 300, 400]
s = Series(data)
print(s)
print(type(s))
0 100
1 200
2 300
3 400
dtype: int64
<class 'pandas.core.series.Series'>
from pandas import Series
date = ['2018-08-01', '2018-08-02', '2018-08-03', '2018-08-04', '2018-08-05']
xrp_close = [512, 508, 512, 507, 500]
s = Series(xrp_close, index=date)
print(s)
print(s[0])
print(s['2018-08-01'])
2018-08-01 512
2018-08-02 508
2018-08-03 512
2018-08-04 507
2018-08-05 500
dtype: int64
512
512
from pandas import Series
date = ['2018-08-01', '2018-08-02', '2018-08-03', '2018-08-04', '2018-08-05']
xrp_close = [512, 508, 512, 507, 500]
s = Series(xrp_close, index=date)
print(s.index)
print(s.values)
Index(['2018-08-01', '2018-08-02', '2018-08-03', '2018-08-04', '2018-08-05'], dtype='object')
[512 508 512 507 500]
from pandas import Series
date = ['2018-08-01', '2018-08-02', '2018-08-03', '2018-08-04', '2018-08-05']
xrp_close = [512, 508, 512, 507, 500]
s = Series(xrp_close, index=date)
print(s['2018-08-01': '2018-08-03'])
print(s[0:2])
2018-08-01 512
2018-08-02 508
2018-08-03 512
dtype: int64
2018-08-01 512
2018-08-02 508
dtype: int64
from pandas import Series
date = ['2018-08-01', '2018-08-02', '2018-08-03', '2018-08-04', '2018-08-05']
xrp_close = [512, 508, 512, 507, 500]
s = Series(xrp_close, index=date)
s['2018-08-06'] = 490
print(s.drop('2018-08-01'))
print(s)
연산
my_list = [100, 200, 300, 400]
# print (my_list / 10) # error - 딕셔너리는 이런 연산이 불가능
# 아래처럼 불편하게 연산을 진행해야 한다
new_list = []
for val in my_list:
new_list.append(val/10)
from pandas import Series
s = Series([100, 200, 300, 400])
# pandas로 간단하게 연산가능
print(s /10)