LernerPython blog, from Reuven Lerner: Pandas Grouper: Group datetime columns by custom time periods

1 month ago 14
Club.noww.in
 Group datetime columns by custom time periods

Want to change the granularity when grouping on a Python Pandas data frame’s datetime column?

Use Grouper.

For example: Here we get the mean trip_distance per 14-day period:

df.groupby(pd.Grouper(key='tpep_pickup_datetime', freq='14D'))['trip_distance'].mean()

The post Pandas Grouper: Group datetime columns by custom time periods appeared first on LernerPython.

Read Entire Article