Python Pandas - Display the end time of the custom business hour in 24h format from the BusinessHour offset object

PythonServer Side ProgrammingProgramming

To display the end time of the custom business hour in 24h format from the BusinessHour offset object, use the BusinessHour.end 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 −

print("
Updated Timestamp...
",timestamp + bhOffset)

Display the end time of the custom business hour −

print("
The end time of the custom business hour...
",bhOffset.end)

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...
",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("
BusinessHour Offset...
",bhOffset) # Display the Updated Timestamp print("
Updated Timestamp...
",timestamp + bhOffset) # Display the end time of the custom business hour print("
The end time of the custom business hour...
",bhOffset.end)

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 end time of the custom business hour...
 (datetime.time(18, 0),)
raja
Updated on 21-Oct-2021 08:57:22

Advertisements