假设你真的想要,而不是 '2017年11月7日' 在 '2017年7月11日' 开始(这是你的 '2017年7月23日')结束日期后,您可以使用Partial String Indexing:
SETUP
df = pd.DataFrame(index = pd.date_range('2017-05-07 00:00:00+00:00','2017-07-27 23:50:00+00:00', freq='10T'))
print(df.index)
DatetimeIndex(['2017-05-07 00:00:00+00:00', '2017-05-07 00:10:00+00:00',
'2017-05-07 00:20:00+00:00', '2017-05-07 00:30:00+00:00',
'2017-05-07 00:40:00+00:00', '2017-05-07 00:50:00+00:00',
'2017-05-07 01:00:00+00:00', '2017-05-07 01:10:00+00:00',
'2017-05-07 01:20:00+00:00', '2017-05-07 01:30:00+00:00',
...
'2017-07-27 22:20:00+00:00', '2017-07-27 22:30:00+00:00',
'2017-07-27 22:40:00+00:00', '2017-07-27 22:50:00+00:00',
'2017-07-27 23:00:00+00:00', '2017-07-27 23:10:00+00:00',
'2017-07-27 23:20:00+00:00', '2017-07-27 23:30:00+00:00',
'2017-07-27 23:40:00+00:00', '2017-07-27 23:50:00+00:00'],
dtype='datetime64[ns, UTC]', length=11808, freq='10T')
现在,使用部分字符串索引与切片:
df1 = df['2017-07-11':'2017-07-22 23:50:00']
print(df_1.index)
输出:随着时间的推移较小的数据帧之前,2017年7月11日和2017年7月22日23:50后下降:
DatetimeIndex(['2017-07-11 00:00:00+00:00', '2017-07-11 00:10:00+00:00',
'2017-07-11 00:20:00+00:00', '2017-07-11 00:30:00+00:00',
'2017-07-11 00:40:00+00:00', '2017-07-11 00:50:00+00:00',
'2017-07-11 01:00:00+00:00', '2017-07-11 01:10:00+00:00',
'2017-07-11 01:20:00+00:00', '2017-07-11 01:30:00+00:00',
...
'2017-07-22 22:20:00+00:00', '2017-07-22 22:30:00+00:00',
'2017-07-22 22:40:00+00:00', '2017-07-22 22:50:00+00:00',
'2017-07-22 23:00:00+00:00', '2017-07-22 23:10:00+00:00',
'2017-07-22 23:20:00+00:00', '2017-07-22 23:30:00+00:00',
'2017-07-22 23:40:00+00:00', '2017-07-22 23:50:00+00:00'],
dtype='datetime64[ns, UTC]', length=1728, freq='10T')