ใช้ property CustomBusinessHour.next_bday เพื่อไปยังวันทำการถัดไป (next business day)
ขั้นตอน
- import pandas as pd
- สร้าง timestamp และ CustomBusinessHour offset
- เข้าถึง
cbhOffset.next_bdayและบวกกับ timestamp
ตัวอย่างโค้ด
import pandas as pd
timestamp = pd.Timestamp('2021-12-20 08:35:10')
cbhOffset = pd.tseries.offsets.CustomBusinessHour(start='09:30', end='18:00', n=5, weekmask='Mon Tue Wed Fri')
print("Timestamp...\n", timestamp)
print("\nCustomBusinessHour Offset...\n", cbhOffset)
print("\nThe next business day...\n", timestamp + cbhOffset.next_bday)
ผลลัพธ์
Timestamp... 2021-12-20 08:35:10 CustomBusinessHour Offset... <5 * CustomBusinessHours: CBH=09:30-18:00> The next business day... 2021-12-21 08:35:10