pandas复习

pandas 复习

时间索引

  • 取值容易
  • 高低频时间转换

dates = [datetime(2016,1,1),datetime(2016,1,2),datetime(2016,1,3)]
ts=pd.Series([1,2,3],index=dates)
ts.index[0] 
ts['20160101']
ts['2016-01-01']
ts['01/01/2016']
ts['2016']

rts=ts.resample('M',how='first') #'M'指的是每月最后一天

shift 操作


price=pd.Series([20.34,20.56,21.01,20.65,21.34],\
                index=pd.to_datetime(['2016-01-01','2016-01-02',\
				                '2016-01-03','2016-01-04','2016-01-05']))
(price-price.shift(1))/price.shift(1)


Loading Disqus comments...
Table of Contents