[英]How to remove a certain time period from a dataframe with timestamp index?
I have a DataFrame that is something like this: 我有一个像这样的DataFrame:
Datetime Open Low/Open Close/Open Tar
1998-01-30 15:30:00 68.02 0.997501 0.999706 0
1998-01-30 15:45:00 67.91 0.998086 1.000736 0
1998-01-30 16:00:00 67.96 0.998676 1.000589 0
1998-01-30 16:15:00 67.96 1.000000 1.000000 0
the timestamp is 24 hours, however, I only want the data points that have index between 9:30:00 to 16:00:00. 时间戳是24小时,但是,我只希望索引在9:30:00到16:00:00之间的数据点。 How do I remove all the data points outside of what I need? 如何删除我需要的所有数据点?
The .dt
suffix of any datetime column has array-friendly routines. 任何datetime列的.dt
后缀都有数组友好的例程。
import datetime
df[(df.Datetime.dt.time >= datetime.time(9, 30)) &
(df.Datetime.dt.time <= datetime.time(16, 0))]
From your sample, I get: 从您的样本中,我得到:
Datetime Open Low/Open Close/Open Tar
0 1998-01-30 15:30:00 68.02 0.997501 0.999706 0
1 1998-01-30 15:45:00 67.91 0.998086 1.000736 0
2 1998-01-30 16:00:00 67.96 0.998676 1.000589 0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.