我有一个DataFrame,其布局与以下类似:
In [24]: example_df
Out[24]:
Price
DateTime
2012-09-11 19:44:00 99.622
2012-09-11 19:45:00 99.312
2012-09-11 19:46:00 99.211
2012-09-11 19:47:00 99.757
2012-09-11 19:48:00 99.312
2012-09-11 19:49:00 99.157
2012-09-11 19:50:00 99.751
...
DataFrame具有日期时间索引。
这个DataFrame每分钟跨度很多年,我该如何将数据切片为仅包含时间序列中每天的特定时间段?在DataFrame中每天说12:00-13:00?
您可以indexer_between_time()
用来捕获给定时间间隔内的索引,然后iloc
对DataFrame进行切片。例如:
>>> df.iloc[df.index.indexer_between_time('19:45:00', '19:49:00')]
Price
2012-09-11 19:45:00 99.312
2012-09-11 19:46:00 99.211
2012-09-11 19:47:00 99.757
2012-09-11 19:48:00 99.312
2012-09-11 19:49:00 99.157
对于每天12:00至13:00之间的特定输入请求,可以使用以下命令获取行:
df.iloc[df.index.indexer_between_time('12:00:00', '13:00:00')]
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句