Common resampling frequencies in pandas are specified using string aliases. Here are some of the most frequently used ones:
Common Resampling Frequencies:
- 'B': Business day frequency (excludes weekends)
- 'D': Calendar day frequency
- 'H': Hourly frequency
- 'T' or 'min': Minute frequency
- 'S': Second frequency
- 'M': Month-end frequency
- 'MS': Month-start frequency
- 'Q': Quarter-end frequency
- 'QS': Quarter-start frequency
- 'A' or 'Y': Year-end frequency
- 'AS' or 'YS': Year-start frequency
- 'W': Weekly frequency (default is Sunday as the end of the week)
- 'BM': Business month-end frequency
- 'BMS': Business month-start frequency
- 'BQ': Business quarter-end frequency
- 'BQS': Business quarter-start frequency
- 'BA' or 'BY': Business year-end frequency
- 'BAS' or 'BYS': Business year-start frequency
Example Usage:
Here’s an example of how to use some of these frequencies with the resample method:
import pandas as pd
# Sample time series data
date_rng = pd.date_range(start='2023-01-01', end='2023-01-10', freq='D')
data = {'value': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]}
df = pd.DataFrame(data, index=date_rng)
# Resample to get the weekly sum
weekly_sum = df.resample('W').sum()
# Resample to get the monthly mean
monthly_mean = df.resample('M').mean()
print("Weekly Sum:\n", weekly_sum)
print("\nMonthly Mean:\n", monthly_mean)
In this example, the DataFrame is resampled to calculate the weekly sum and monthly mean of the values. You can choose the frequency that best fits your analysis needs.
