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

Lấy ngày làm việc tiếp theo từ CustomBusinessHour trong Pandas

Sử dụng thuộc tính CustomBusinessHour.next_bday để lấy offset đến ngày làm việc tiếp theo.

Ví dụ

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:", timestamp)
print("CustomBusinessHour Offset:", cbhOffset)
print("Next business day:", timestamp + cbhOffset.next_bday)

Kết quả

Timestamp: 2021-12-20 08:35:10
CustomBusinessHour Offset: <5 * CustomBusinessHours: CBH=09:30-18:00>
Next business day: 2021-12-21 08:35:10