[英]Filter Pandas DataFrame by time index
I have a pandas DataFrame from 6:36 AM to 5:31 PM.我从早上 6:36 到下午 5:31 有一个 pandas DataFrame。 I want to remove all observations where the time is less than 8:00:00 AM.
我想删除时间小于上午 8:00:00 的所有观察结果。 Here is my attempt:
这是我的尝试:
df = df[df.index < '2013-10-16 08:00:00']
This does nothing, please help.这没有任何作用,请帮助。
You want df.loc[df.index < '2013-10-16 08:00:00']
since you're selecting by label (index) and not by value.您想要
df.loc[df.index < '2013-10-16 08:00:00']
因为您是按标签(索引)而不是按值选择。
您可以使用query
来获得更简洁的选项:
df.query("index < '2013-10-16 08:00:00'")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.