Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filter by hour in Pandas

Tags:

python

pandas

How can I filter a DataFrame indexed by datetime so that I get only the entries within certain hours of every day?

I am looking for something equivalent to the following R code for an xts object

df["09:00:00::17:00:00"]
like image 986
em70 Avatar asked Nov 17 '13 22:11

em70


2 Answers

You want the between_time method: http://pandas.pydata.org/pandas-docs/dev/generated/pandas.DataFrame.between_time.html#pandas.DataFrame.between_time

like image 72
TomAugspurger Avatar answered Oct 19 '22 16:10

TomAugspurger


Hope this helps: df[(df.Time > '08:00') & (df.Time < '08:05')]

like image 23
Manre Avatar answered Oct 19 '22 16:10

Manre