Change language

Python | Pandas tseries.offsets.BusinessHour.next_bday

| |

DateOffsets can be created to move dates by a specified number of valid dates. For example, Bday (2) can be added to a date to move it two business days forward. If the date does not start with a valid date, it is first moved to a valid date and then an offset is generated.

Pandas Function tseries.offsets.BusinessHour.next_bday used to go to the next business day.

Syntax: pandas.tseries.offsets.BusinessHour.next_bday

Parameter: None

Returns: offset

Example # 1: Use the pandas.tseries function .offsets.BusinessHour.next_bday to move the specified timestamp to the next business day.

# import pandas as pd

import pandas as pd

 
# Create a timestamp

ts = pd.Timestamp ( ’2019 -10-10 07: 15: 11’ )

 
# Create offset 5 business hours

bh = pd.tseries.offsets.BusinessHour (n = 5 )

 
# Print time stamp

print (ts)

 
# Print offset

print (bh)

Exit:

Now we will add the working hour offset to this object timestamps to increment the datetime value. We will also move the specified timestamp to the next business day.

# Adding a business hour offset to the specified time stamp

new_timestamp = ts + bh

 
# Print updated tag time

print (new_timestamp)

 
# Move timestamp to next
# weekday

result = ts + bh.next_bday

< p>  
# Print result

print (result)

Output:

As we can see from the output, we have successfully created an offset of 5 business hours and added it to the specified timestamp. We also moved this timestamp to the next business day.

Example # 2: Use pandas.tseries.offsets.BusinessHour () to create an offset in 10 days and 5 pandas.tseries.offsets.BusinessHour () hours.

# import pandas as pd

import pandas as pd

 
# Create a timestamp

ts = pd.Timestamp ( ’ 2019-10-10 07: 15: 11’ )

 
# Create offset

bh = pd.tseries.of fsets.BusinessHour (offset = datetime.timedelta (days = 10 , hours = 10 ))

 
# Print time stamp

print (ts)

 
# Print offset

print (bh)

Output:

Now we will add a business hour offset to this timestamp object to increase the value datetime. We will also move the specified timestamp to the next business day.

# Adding a business hour offset to the specified time stamp

new_timestamp = ts + bh

 
# Print updated tag time

print (new_timestamp)

 
# Move timestamp to next
# weekday

result = ts + bh.next_bday

< p>  
# Print result

print (result)

Output:

Note. Although we spent 10 days on the feature, please note how the business hour value changes.

As we can see in the output, we have successfully created an offset and added it to the given timestamp. We also moved this timestamp to the next business day.