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
forname,groupindf.groupby(df.timestampe.dt.minute%10):printprint(name)print(group)1timestampetext02016-08-11 12:01:00 a12016-08-13 11:11:00 b3timestampetext22016-08-09 11:13:00 c32016-08-05 11:33:00 d52016-08-21 11:43:00 f7timestampetext42016-08-19 11:27:00 e
Post a Comment for "Panda How To Groupby Rows Into Different Time Buckets?"