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