
- 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 the count of increments applied on the given DateOffset object
To return the count of increments applied on the given DateOffset object, use the offset.n property in Pandas. At first, import the required libraries −
from pandas.tseries.frequencies import to_offset import pandas as pd
Set the timestamp object in Pandas −
timestamp = pd.Timestamp('2021-09-26 03:25:02.000045')
Create the DateOffset. We are incrementing the months here using the "M" frequency −
offset = to_offset("5M")
Display the Updated Timestamp −
print("\nUpdated Timestamp...\n",timestamp + offset)
Return the count of increments on the given DateOffset object −
print("\nThe count of increments on the DateOffset object..\n", offset.n)
Example
Following is the code −
from pandas.tseries.frequencies import to_offset import pandas as pd # Set the timestamp object in Pandas timestamp = pd.Timestamp('2021-09-26 03:25:02.000045') # Display the Timestamp print("Timestamp...\n",timestamp) # Create the DateOffset # We are incrementing the months here using the "M" frequency offset = to_offset("5M") # Display the DateOffset print("\nDateOffset...\n",offset) # Display the Updated Timestamp print("\nUpdated Timestamp...\n",timestamp + offset) # return the count of increments on the given DateOffset object print("\nThe count of increments on the DateOffset object..\n", offset.n)
Output
This will produce the following code −
Timestamp... 2021-09-26 03:25:02.000045 DateOffset... <5 * MonthEnds> Updated Timestamp... 2022-01-31 03:25:02.000045 The count of increments on the DateOffset object.. 5
- Related Articles
- Python Pandas - Return the frequency applied on the given DateOffset object
- Python Pandas - Return the rule code applied on the given DateOffset object
- Python Pandas - Return frequency applied on the given DateOffset object as a string
- Python Pandas - Return the count of increments applied on the BusinessDay offset
- Python Pandas - Return the count of increments applied on the BusinessHour offset
- Python Pandas - Return the count of increments applied on the CustomBusinessDay offset
- Python Pandas - Return the count of increments applied on the CustomBusinessHour offset
- Python Pandas - Return the number of nanoseconds in the given DateOffset 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
- Python Pandas - Return the rule code applied on the given CustomBusinessDay object
- Python Pandas - Return the rule code applied on the given CustomBusinessHour 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

Advertisements