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
Python Pandas - Display the keyword arguments applied on the given BusinessDay object
The BusinessDay offset in Pandas allows you to work with business days while applying additional time offsets. The kwds property displays the keyword arguments that were used when creating the BusinessDay object.
Understanding BusinessDay Offset
BusinessDay is a DateOffset subclass that represents business day intervals, automatically skipping weekends. You can add additional time offsets using the offset parameter ?
import datetime
import pandas as pd
# Create a timestamp
timestamp = pd.Timestamp('2021-10-30 01:55:02.000045')
print("Original Timestamp:")
print(timestamp)
Original Timestamp: 2021-10-30 01:55:02.000045
Creating BusinessDay with Offset
Create a BusinessDay offset with additional hours and minutes using datetime.timedelta ?
import datetime
import pandas as pd
# Create BusinessDay offset with additional time
bd_offset = pd.tseries.offsets.BusinessDay(
offset=datetime.timedelta(hours=7, minutes=7)
)
print("BusinessDay Offset:")
print(bd_offset)
print("\nOffset details:", bd_offset.offset)
BusinessDay Offset: <BusinessDay: offset=datetime.timedelta(seconds=25620)> Offset details: 7:07:00
Displaying Keyword Arguments
Use the kwds property to display all keyword arguments applied to the BusinessDay object ?
import datetime
import pandas as pd
# Create timestamp and BusinessDay offset
timestamp = pd.Timestamp('2021-10-30 01:55:02.000045')
bd_offset = pd.tseries.offsets.BusinessDay(
offset=datetime.timedelta(hours=7, minutes=7)
)
# Display the keyword arguments
print("Keyword arguments on BusinessDay Offset:")
print(bd_offset.kwds)
# Apply the offset
updated_timestamp = timestamp + bd_offset
print("\nUpdated Timestamp:")
print(updated_timestamp)
Keyword arguments on BusinessDay Offset:
{'offset': datetime.timedelta(seconds=25620)}
Updated Timestamp:
2021-11-01 09:02:02.000045
Complete Example
Here's a comprehensive example showing BusinessDay offset creation and keyword argument display ?
import datetime
import pandas as pd
# Set the timestamp object in Pandas
timestamp = pd.Timestamp('2021-10-30 01:55:02.000045')
# Display the Timestamp
print("Timestamp...")
print(timestamp)
# Create the BusinessDay Offset
# BusinessDay is the DateOffset subclass
bd_offset = pd.tseries.offsets.BusinessDay(
offset=datetime.timedelta(hours=7, minutes=7)
)
# Display the BusinessDay Offset
print("\nBusinessDay Offset...")
print(bd_offset)
# Display the Updated Timestamp
print("\nUpdated Timestamp...")
print(timestamp + bd_offset)
# Return the frequency applied on the given BusinessDay object as a string
print("\nFrequency on the given BusinessDay Offset...")
print(bd_offset.freqstr)
# Display the keyword arguments
print("\nKeyword arguments on the given BusinessDay Offset...")
print(bd_offset.kwds)
Timestamp...
2021-10-30 01:55:02.000045
BusinessDay Offset...
<BusinessDay: offset=datetime.timedelta(seconds=25620)>
Updated Timestamp...
2021-11-01 09:02:02.000045
Frequency on the given BusinessDay Offset...
B+7H7Min
Keyword arguments on the given BusinessDay Offset...
{'offset': datetime.timedelta(seconds=25620)}
Key Properties
| Property | Description | Return Type |
|---|---|---|
kwds |
Keyword arguments used in creation | Dictionary |
freqstr |
Frequency string representation | String |
offset |
Additional time offset | timedelta |
Conclusion
The kwds property provides insight into the keyword arguments used when creating a BusinessDay offset. This is particularly useful for debugging and understanding the configuration of your date offset objects.
