Reputation: 399
I have a dataframe like this:
X Y
1999-09-05 09:00:00 15.4 1.0
1999-09-05 11:00:00 18.1 0.0
1999-09-05 12:00:00 18.8 1.0
1999-09-05 13:00:00 19.3 0.0
1999-09-05 14:00:00 18.8 0.0
....
The dataframe has a X and a Y column for every Hour of a day.
I want extra dataframes for every Hour of a day
Like this:
df 01:00
1999-09-05 01:00:00 13.4 1.0
1999-09-06 01:00:00 13.8 1.0
1999-09-07 01:00:00 15.4 1.0
...
df 23:00
1999-09-05 23:00:00 13.4 1.0
1999-09-06 23:00:00 13.8 1.0
1999-09-07 23:00:00 15.4 1.0
I tried to use the df.loc function but i failed.
df.loc[df.index == '08:00:00']
Another way to solve my problem would be:
How can i filter just the time in dataframes?
Like i want to calculate .mean() for every row with the time 08:00 in the index
Upvotes: 2
Views: 601
Reputation: 5696
Assuming your data is in df
and the datetime
column is the index,
You can use df.loc[df.index.to_series().dt.hour == 8]
Upvotes: 3