数据小站
数据科学成长之路

pandas时间序列

pandas处理时间序列对象,主要是操作 DatetimeIndex和PeriodIndex 对象。

pandas时间戳序列 :DatetimeIndex对象

 date_range函数
               pd.date_range('2018/12/1',periods=31)

 读取csv/excel时指定index_col、parse_dates关键字
               df = pd.read_csv(path, engine='python', encoding='utf_8_sig', 
                                index_col=0, parse_dates=True)

 df.index = pd.to_datetime(df['col'])
               df.index = pd.to_datetime(df['Unnamed: 0'])

pd.DatetimeIndex
               pd.DatetimeIndex(['2018/4/14','2019/4/14'])

pandas时期对象 :PeriodIndex对象

pd.period_range
通过pd.PeriodIndex创建
把分开放在不同列中的时间信息合并成一个PeriodIndex

DatetimeIndex

赞(0) 打赏
未经允许不得转载:技术文档分享 » pandas时间序列

评论 抢沙发