ใช้ property CustomBusinessHour.rule_code เพื่อคืนรหัสกติกา (rule code) ของความถี่ที่ใช้กับ CustomBusinessHour offset
ขั้นตอน
- import pandas as pd
- สร้าง timestamp และ CustomBusinessHour offset พร้อม normalize=True
- เข้าถึง
cbhOffset.rule_code
ตัวอย่างโค้ด
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...\n", timestamp)
print("\nCustomBusinessHour Offset...\n", cbhOffset)
print("\nUpdated Timestamp...\n", timestamp + cbhOffset)
print("\nFrequency applied on the given CustomBusinessHour Offset object...\n", cbhOffset.freqstr)
print("\nThe rule code of the CustomBusinessHour object..\n", cbhOffset.rule_code)
ผลลัพธ์
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 applied on the given CustomBusinessHour Offset object... 4CBH The rule code of the CustomBusinessHour object.. CBH