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.