Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Lấy rule_code của CustomBusinessHour trong Pandas

Sử dụng thuộc tính CustomBusinessHour.rule_code để lấy mã quy tắc tần suất (ví dụ: 'CBH').

Ví dụ

import pandas as pd

timestamp = pd.Timestamp('2021-11-14 05:20:30')
cbhOffset = pd.tseries.offsets.CustomBusinessHour(n=4, weekmask='Mon Tue Wed Fri Sat', normalize=True)

print("Timestamp:", timestamp)
print("CustomBusinessHour Offset:", cbhOffset)
print("Updated Timestamp:", timestamp + cbhOffset)
print("Frequency string:", cbhOffset.freqstr)
print("Rule code:", cbhOffset.rule_code)

Kết quả

Timestamp: 2021-11-14 05:20:30
CustomBusinessHour Offset: <4 * CustomBusinessHours: CBH=09:00-17:00>
Updated Timestamp: 2021-11-15 00:00:00
Frequency string: 4CBH
Rule code: CBH