python开发笔记-如何做数据准备

   时间格式:

>>> from datetime import date  
>>> firstday = date.fromtimestamp(1464010200)  
>>> lastday = date.fromtimestamp(1495200600)  
>>> firstday  
datetime.date(2018, 2, 23)  
>>> lastday  
datetime.date(2018, 2, 19)  

 创建时间序列:

    

 import pandas as pd  
>>> dates=pd.date_range('20180220',periods=7)  
>>> dates  
DatetimeIndex(['2018-02-20', '2018-02-21', '2018-02-22', '2018-02-23',  
               '2018-02-24', '2017-05-25', '2017-05-26'],  
              dtype='datetime64[ns]', freq='D')  
>>> import numpy as np  
>>> datesdf=pd.DataFrame(np.random.randn(7,3),index=dates,columns=list('ABC'))  
>>> datesdf  
                   A         B         C  
2018-02-20  0.659181 -0.020180 -0.182932  
2018-02-21  0.602556  0.090524 -0.404592  
2018-02-22  0.400426  0.090271 -0.835928  
2018-02-23  0.497099 -1.977787  0.771407  
2018-02-24  0.078308  0.155671  0.630712  
2018-02-25 -0.442369  1.510636 -0.679247  
2018-02-26 -0.318323 -0.312514  0.753957  

  

原文地址:https://www.cnblogs.com/68xi/p/8564480.html