![]() |
VOOZH | about |
Resampling is the process of changing the frequency of time-indexed data for example, converting daily data into weekly, monthly, or quarterly intervals. In Pandas, resample() is used to perform such time-based grouping and aggregation.
During resampling, functions like .mean() are used to combine all values within each new time interval and return their average. This helps summarize time-grouped data efficiently.
The syntax below shows how the resample() function is applied on a DataFrame or Series:
DataFrame.resample(rule, axis=0, closed=None, label=None, on=None, level=None)
Parameters:
We will use this dataset in all examples below.
Output
To download the file "apple.csv" used in this article, click here
Example 1: This example groups daily closing prices into monthly buckets and calculates the monthly average using "ME" (Month-End).
Output
Explanation:
Example 2: This example resamples opening prices into weekly groups and computes the average opening price per week.
Output
Explanation:
Example 3: This example converts daily opening prices into quarterly groups and calculates the quarterly averages using "QE" (Quarter-End).
Output
Explanation: