Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

Python Pandas CustomBusinessHour offset object - ไปยังวันทำการถัดไป

ใช้ property CustomBusinessHour.next_bday เพื่อไปยังวันทำการถัดไป (next business day)

ขั้นตอน

  1. import pandas as pd
  2. สร้าง timestamp และ CustomBusinessHour offset
  3. เข้าถึง 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