
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python Pandas - Return frequency applied on the given DateOffset object as a string
To return frequency applied on the given DateOffset object as a string, use the offset.freqstr property in Pandas.
At first, import the required libraries −
from pandas.tseries.offsets import DateOffset import pandas as pd
Set the timestamp object in Pandas −
timestamp = pd.Timestamp('2021-08-30 02:30:55')
Create the DateOffset. We are incrementing the months here using the "months" parameter −
offset = pd.tseries.offsets.DateOffset(months=3)
Display the Updated Timestamp −
print("\nUpdated Timestamp...\n",timestamp + offset)
Frequency applied on the given DateOffset object as a string −
print("\nFrequency on the given DataOffset...\n",offset.freqstr)
Example
Following is the code −
from pandas.tseries.offsets import DateOffset import pandas as pd # Set the timestamp object in Pandas timestamp = pd.Timestamp('2021-08-30 02:30:55') # Display the Timestamp print("Timestamp...\n",timestamp) # Create the DateOffset # We are incrementing the months here using the "months" parameter offset = pd.tseries.offsets.DateOffset(months=3) # Display the DateOffset print("\nDateOffset...\n",offset) # Display the Updated Timestamp print("\nUpdated Timestamp...\n",timestamp + offset) # frequency applied on the given DateOffset object as a string print("\nFrequency on the given DataOffset...\n",offset.freqstr)
Output
This will produce the following code −
Timestamp... 2021-08-30 02:30:55 DateOffset... <DateOffset: months=3> Updated Timestamp... 2021-11-30 02:30:55 Frequency on the given DataOffset... <DateOffset: months=3>
- Related Articles
- Python Pandas - Return the frequency applied on the given DateOffset object
- Python Pandas - Return frequency applied on the given BusinessDay Offset object as a string
- Python Pandas - Return frequency applied on the given BusinessHour Offset object as a string
- Python Pandas - Return frequency applied on the given CustomBusinessDay Offset object as a string
- Python Pandas - Return frequency applied on the given CustomBusinessHour Offset object as a string
- Python Pandas - Return the rule code applied on the given DateOffset object
- Python Pandas - Return the count of increments applied on the given DateOffset object
- Python Pandas - Return the string alias of the Time series frequency applied on the given Period object
- Python Pandas - Return the name of the frequency applied on the given BusinessDay offset object
- Python Pandas - Return the name of the frequency applied on the given BusinessHour offset object
- Python Pandas - Return the name of the frequency applied on the given CustomBusinessDay offset object
- Python Pandas - Return the name of the frequency applied on the given CustomBusinessHour offset object
- Python Pandas - Return the frequency object as a string from the PeriodIndex object
- Python Pandas - Return the rule code applied on the given BusinessDay object
- Python Pandas - Return the rule code applied on the given BusinessHour object

Advertisements