Change language

Python | Pandas tseries.offsets.BusinessDay.freqstr

| |

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.

tseries.offsets.BusinessDay.freqstr Pandas tseries.offsets.BusinessDay.freqstr returns the frequency applied to this object as a string offset.

Syntax: pandas.tseries.offsets.BusinessDay.freqstr

Parameter: None

Returns: offset frequency as string

Example # 1: Use the pandas.tseries.offsets.BusinessDay.freqstr attribute to return the frequency applied to this pandas offset object .tseries.offsets.BusinessDay.freqstr days, as a string.

# import pandas as pd

import pandas as pd

 
# Create a timestamp

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

 
# Create offset 5 business days

bd = pd.tseries.offsets.BusinessDay (n = 5 )

 
# Print time stamp

print (ts)

 
# Print DateOffset

print (bd)

Output:

Now we will add the workday offset to this timestamp object to increase the datetime value. We will also print the frequency applied to this offset object.

# Add a workday offset to this time stamp

new_timestamp = ts + bd

 
# Print updated tag time

print (new_timestamp)

 
# Print the frequency applied to
# given offset object

print (bd.freqstr)

Output:

As we can see from the output, we have successfully created an offset of 5 business days and added it to the given timestamp. We also printed the frequency applied to this offset object as a string.

Example # 2: Use the pandas.tseries.offsets.BusinessDay.freqstr attribute to return the frequency applied to this pandas.tseries.offsets.BusinessDay.freqstr offset object as a string.

# import pandas as pd

import pandas as pd

 
# import to_offset

from pandas.tseries.frequencies import to_offset

 
# Create a timestamp

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

 
# Create offset 10 business days and 10 hours

bd = pd.tseries.offsets.BusinessDay (offset = datetime.timedelta (days = 10 , hours = 10 ))

 
# Print time stamp

print (ts)

 
# Print DateOffset

pr int (bd)

Output:

We will now add the workday offset to this timestamp object to increase the datetime value. We will also print the frequency applied to the given offset object.

# Add a workday offset to this time stamp

new_timestamp = ts + bd

 
# Print updated tag time

print (new_timestamp)

 
# Print the frequency applied to
# given offset object

print (bd.freqstr)

Output:

As we can see from the output, we have successfully created an offset of 10 business days and 10 hours and added it to the given time stamp. We also printed the frequency applied to the given offset object as a string.