Resampling
Resampling
You’ve grouped df
by the day of the week with df.groupby(day_names)["co"].mean()
. Now consider something different. What if you wanted to group by an observation’s year and quarter? Here’s one way to accomplish that:
This whole operation can, alternatively, be expressed through resampling. One of the uses of resampling is as a time-based groupby. All that you need to do is pass a frequency string, such as "Q"
for "quarterly"
, and Pandas will do the rest:
Often, when you use .resample()
you can express time-based grouping operations in a much more succinct manner. The result may be a tiny bit different than the more verbose .groupby()
equivalent, but you’ll often find that .resample()
gives you exactly what you’re looking for
Comments (0)