import numpy as np
import pandas as pd
# pd.period_range()创建时期范围
# 数据格式为PeriodIndex,单个数值为Period
periods = pd.period_range(start='1/1/2011', end='1/1/2012', freq='M')
print("periods = {0}, type(periods) = {1}".format(periods, type(periods)))
print("-" * 50)
print("periods[0] = {0}, type(periods[0]) = {1}".format(periods[0], type(periods[0])))
print("-" * 100)
打印结果:
periods = PeriodIndex(['2011-01', '2011-02', '2011-03', '2011-04', '2011-05', '2011-06',
'2011-07', '2011-08', '2011-09', '2011-10', '2011-11', '2011-12',
'2012-01'],
dtype='period[M]', freq='M'), type(periods) = <class 'pandas.core.indexes.period.PeriodIndex'>
--------------------------------------------------
periods[0] = 2011-01, type(periods[0]) = <class 'pandas._libs.tslibs.period.Period'>
----------------------------------------------------------------------------------------------------