Python 按时间索引过滤 Pandas DataFrame

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20233071/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 19:56:42  来源:igfitidea点击:

Filter Pandas DataFrame by time index

pythonpandas

提问by user2113095

I have a pandas DataFrame from 6:36 AM to 5:31 PM. I want to remove all observations where the time is less than 8:00:00 AM. Here is my attempt:

我有一个从早上 6:36 到下午 5:31 的 Pandas DataFrame。我想删除时间小于上午 8:00:00 的所有观察结果。这是我的尝试:

df = df[df.index < '2013-10-16 08:00:00']

This does nothing, please help.

这没有任何作用,请帮忙。

采纳答案by Kevin Stone

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']因为您是按标签(索引)而不是按值选择的。

selecting by label

按标签选择