Panda How To Groupby Rows Into Different Time Buckets?
I have a dataframe with a datetime type column called timestamp, I want to split the dataframe into several dataframes based on timestamp the time part, each dataframe contains row
Solution 1:
Your main tools will be df.timestampe.dt.minute % 10
and groupby
.
I used an apply(pd.DataFrame.reset_index)
just as a convenience to illustrate
df.groupby(df.timestampe.dt.minute % 10).apply(pd.DataFrame.reset_index)
Just using the groupby
could be advantageous as well
for name, group in df.groupby(df.timestampe.dt.minute % 10):
print
print(name)
print(group)
1
timestampe text
0 2016-08-11 12:01:00 a
1 2016-08-13 11:11:00 b
3
timestampe text
2 2016-08-09 11:13:00 c
3 2016-08-05 11:33:00 d
5 2016-08-21 11:43:00 f
7
timestampe text
4 2016-08-19 11:27:00 e
Post a Comment for "Panda How To Groupby Rows Into Different Time Buckets?"