![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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 - Display the start time of the custom business hour in 24h format from the BusinessHour offset object
To display the start time of the custom business hour in 24h format from the BusinessHour offset object, use the BusinessHour.start property.
At first, import the required libraries −
import pandas as pd
Set the timestamp object in Pandas −
timestamp = pd.Timestamp('2021-9-30 06:50:20')
Create the BusinessHour Offset. Here, "start" is the start time of your custom business hour in 24h format. The "end" is the end time of your custom business hour in 24h format −
bhOffset = pd.tseries.offsets.BusinessHour(start="09:30", end = "18:00", n = 8)
Display the Updated Timestamp −
Display the start time of the custom business hour −
print("\nThe start time of the custom business hour...\n",bhOffset.start)
Example
Following is the code −
import pandas as pd # Set the timestamp object in Pandas timestamp = pd.Timestamp('2021-9-30 06:50:20') # Display the Timestamp print("Timestamp...\n",timestamp) # Create the BusinessHour Offset # BusinessHour is the DateOffset subclass # Here, "start" is the start time of your custom business hour in 24h format. # The "end" is the end time of your custom business hour in 24h format. bhOffset = pd.tseries.offsets.BusinessHour(start="09:30", end = "18:00", n = 8) # Display the BusinessHour Offset print("\nBusinessHour Offset...\n",bhOffset) # Display the Updated Timestamp print("\nUpdated Timestamp...\n",timestamp + bhOffset) # Display the start time of the custom business hour print("\nThe start time of the custom business hour...\n",bhOffset.start)
Output
This will produce the following code −
Timestamp... 2021-09-30 06:50:20 BusinessHour Offset... <8 * BusinessHours: BH=09:30-18:00> Updated Timestamp... 2021-09-30 17:30:00 The start time of the custom business hour... (datetime.time(9, 30),)
Advertisements