ใช้เมธอด CustomBusinessHour.rollforward() เพื่อเลื่อนวันที่ไปข้างหน้าสู่ offset ถัดไปหากไม่อยู่บน offset
ขั้นตอน
- import pandas as pd
- สร้าง timestamp และ CustomBusinessHour offset
- เรียก
cbhOffset.rollforward(pd.Timestamp('2021-12-30 08:35:10'))
ตัวอย่างโค้ด
import pandas as pd
timestamp = pd.Timestamp('2021-12-20 08:35:10')
cbhOffset = pd.tseries.offsets.CustomBusinessHour(n=5, weekmask='Mon Tue Wed Fri')
print("Timestamp...\n", timestamp)
print("\nCustomBusinessHour Offset...\n", cbhOffset)
print("\nUpdated Timestamp...\n", timestamp + cbhOffset)
roll = cbhOffset.rollforward(pd.Timestamp('2021-12-30 08:35:10'))
print("\nRoll forward Result...\n", roll)
ผลลัพธ์
Timestamp... 2021-12-20 08:35:10 CustomBusinessHour Offset... <5 * CustomBusinessHours: CBH=09:00-17:00> Updated Timestamp... 2021-12-20 14:00:00 Roll forward Result... 2021-12-31 09:00:00