pandas生成时间区间

主要用到函数pd.data_range

https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.date_range.html

pd.date_range(start='1/1/2018', periods=5, freq='M')
#DatetimeIndex(['2018-01-31', '2018-02-28', '2018-03-31', '2018-04-30',
               '2018-05-31'],
              dtype='datetime64[ns]', freq='M')
colnames = data_new.columns.tolist()
timespace = pd.date_range(start='31/10/2017', end='28/2/2019', freq='M').astype(str).str.replace('-','').str.slice(0,6)
for i in timespace:
    colnames.remove(i)

猜你喜欢

转载自blog.csdn.net/yuxeaotao/article/details/89459112