This guide covers how to use the pandas frequency strings within pytimetk. Once you understand key frequencies, you can apply them to manipulate time series data like a pro.
1 Pandas Frequencies
Pandas offers a variety of frequency strings, also known as offset aliases, to define the frequency of a time series. Here are some common frequency strings used in pandas:
βBβ: Business Day
βDβ: Calendar day
βWβ: Weekly
βMβ: Month end
βBMβ: Business month end
βMSβ: Month start
βBMSβ: Business month start
βQβ: Quarter end
βBQβ: Business quarter end
βQSβ: Quarter start
βBQSβ: Business quarter start
βAβ or βYβ: Year end
βBAβ or βBYβ: Business year end
βASβ or βYSβ: Year start
βBASβ or βBYSβ: Business year start
βHβ: Hourly
βTβ or βminβ: Minutely
βSβ: Secondly
βLβ or βmsβ: Milliseconds
βUβ: Microseconds
βNβ: Nanoseconds
Custom Frequencies:
You can also create custom frequencies by combining base frequencies, like:
β2Dβ: Every 2 days
β3Wβ: Every 3 weeks
β4Hβ: Every 4 hours
β1H30Tβ: Every 1 hour and 30 minutes
Compound Frequencies:
You can combine multiple frequencies by adding them together.
β1D1Hβ: 1 day and 1 hour
β1H30Tβ: 1 hour and 30 minutes
Example:
Code
import pandas as pd# Creating a date range with daily frequencydate_range_daily = pd.date_range(start='2023-01-01', end='2023-01-10', freq='D')date_range_daily