Python Pandas - 显示应用于给定 BusinessDay 对象上的关键字参数


如需显示应用于给定 BusinessDay Offset 对象上的关键字参数,请使用 Pandas 中的 BusinessDay.kwds 属性。

首先,导入所需的库 -

import datetime
import pandas as pd

在 Pandas 中设置时间戳对象 -

timestamp = pd.Timestamp('2021-10-30 01:55:02.000045')

创建 BusinessDay Offset。BusinessDay 是 DateOffset 子类 -

bdOffset = pd.tseries.offsets.BusinessDay(offset = datetime.timedelta(hours = 7, minutes = 7))

显示更新后的时间戳 -

print("\nUpdated Timestamp...\n",timestamp + bdOffset)

显示关键字参数 -

print("\nKeyword arguments on the given BusinessDay Offset...\n",bdOffset.kwds)

示例

以下为代码 -

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...\n",timestamp)

# Create the BusinessDay Offset
# BusinessDay is the DateOffset subclass
bdOffset = pd.tseries.offsets.BusinessDay(offset = datetime.timedelta(hours = 7, minutes = 7))

# Display the BusinessDay Offset
print("\nBusinessDay Offset...\n",bdOffset)

# Display the Updated Timestamp
print("\nUpdated Timestamp...\n",timestamp + bdOffset)

# return the frequency applied on the given BusinessDay object as a string
print("\nFrequency on the given BusinessDay Offset...\n",bdOffset.freqstr)

# Display the keyword arguments
print("\nKeyword arguments on the given BusinessDay Offset...\n",bdOffset.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)}

更新日期:2021 年 10 月 21 日

85 次浏览

开启你的 职业生涯

完成课程获得认证

开始学习
广告
© . All rights reserved.