Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
Python Pandas - Display the end time of the custom business hour in 24h format from the BusinessHour offset object
To display the end time of the custom business hour in 24h format from the BusinessHour offset object, use the BusinessHour.end property. This property returns the end time of your custom business hours as a tuple containing datetime.time objects.
Syntax
The basic syntax for creating a BusinessHour offset with custom hours ?
bhOffset = pd.tseries.offsets.BusinessHour(start="HH:MM", end="HH:MM", n=hours) # Access end time using bhOffset.end
Parameters
- start ? Start time of business hours in 24h format (e.g., "09:30")
- end ? End time of business hours in 24h format (e.g., "18:00")
- n ? Number of business hours to add
Example
Following is the complete example demonstrating how to create a BusinessHour offset and display its end time ?
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 end time of the custom business hour
print("\nThe end time of the custom business hour...\n", bhOffset.end)
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 end time of the custom business hour... (datetime.time(18, 0),)
Key Points
- The
endproperty returns a tuple containing datetime.time objects - Business hours are defined in 24-hour format (HH:MM)
- The BusinessHour offset only applies during the specified business hours
- When adding business hours to a timestamp outside business hours, it adjusts to the next business period
Conclusion
Use the BusinessHour.end property to retrieve the end time of custom business hours. This returns the end time as a tuple of datetime.time objects in 24-hour format.
Advertisements
