
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Return Frequency for BusinessDayOffset in Python Pandas
To return frequency applied on the given BusinessDay Offset object as a string, use the BusinessDay.freqstr property in Pandas.
At first, import the required libraries −
import datetime import pandas as pd
Set the timestamp object in Pandas −
timestamp = pd.Timestamp('2021-1-1 01:55:02.000045')
Create the BusinessDay Offset. BusinessDay is the DateOffset subclass −
bdOffset = pd.tseries.offsets.BusinessDay(offset = datetime.timedelta(days = 7, hours = 7, minutes = 7))
Display the Updated Timestamp −
print("\nUpdated Timestamp...\n",timestamp + bdOffset)
Return the frequency applied on the given BusinessDay object as a string −
print("\nFrequency on the given BusinessDay Offset...\n",bdOffset.freqstr)
Example
Following is the code −
import datetime import pandas as pd # Set the timestamp object in Pandas timestamp = pd.Timestamp('2021-1-1 01:55:02.000045') # Display the Timestamp print("Timestamp...\n",timestamp) # Create the BusinessDay Offset # BusinessDay is the DateOffset subclass bdOffset = pd.tseries.offsets.BusinessDay(offset = datetime.timedelta(days = 7, hours = 7, minutes = 7)) # Display the BusinessDay Offset print("BusinessDay Offset...\n",bdOffset) # Display the Updated Timestamp print("\nUpdated Timestamp...\n",timestamp + bdOffset) # return the frequency applied on the given BusinessDay object as a string print("\nFrequency on the given BusinessDay Offset...\n",bdOffset.freqstr)
Output
This will produce the following code −
Timestamp... 2021-01-01 01:55:02.000045 BusinessDay Offset... <BusinessDay: offset=datetime.timedelta(days=7, seconds=25620)> Updated Timestamp... 2021-01-11 09:02:02.000045 Frequency on the given BusinessDay Offset... B+7D7H7Min
Advertisements