- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Pandas - Return the rule code applied on the given DateOffset object
To return the rule code applied on the given DateOffset object, use the offset.rule_code 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("3M")
Display the Updated Timestamp −
print("\nUpdated Timestamp...\n",timestamp + offset)
Return the rule code of the frequency applied on the given DateOffset object −
print("\nThe rule code of the DateOffset object..\n", offset.rule_code)
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("3M") # Display the DateOffset print("\nDateOffset...\n",offset) # Display the Updated Timestamp print("\nUpdated Timestamp...\n",timestamp + offset) # return the rule code of the frequency applied on the given DateOffset object print("\nThe rule code of the DateOffset object..\n", offset.rule_code)
Output
This will produce the following code −
Timestamp... 2021-09-26 03:25:02.000045 DateOffset... <3 * MonthEnds> Updated Timestamp... 2021-11-30 03:25:02.000045 The rule code of the DateOffset object.. M
Advertisements