按时间索引过滤Pandas DataFrame

use*_*095 45 python pandas

我从上午6:36到下午5:31有一个pandas DataFrame.我想删除时间少于8:00:00 AM的所有观察.这是我的尝试:

df = df[df.index < '2013-10-16 08:00:00']
Run Code Online (Sandbox Code Playgroud)

这没什么,请帮忙.

Kev*_*one 69

你想要的df.loc[df.index < '2013-10-16 08:00:00']是你选择标签(索引)而不是价值.

按标签选择

  • 如果有多索引怎么办? (7认同)
  • 没有方便的用例,但我怀疑它是:`df.loc [(df.index ['a'] <something&df.index ['b'] <another_thing)]` (2认同)