ย้ายไปยังวันทำการถัดไปโดยใช้คุณสมบัติ BusinessHour.next_bday ใน Pandas ขั้นแรก นำเข้าไลบรารีที่จำเป็น -
import datetime import pandas as pd
สร้างออฟเซ็ตชั่วโมงธุรกิจ BusinessHour เป็นคลาสย่อย DateOffset -
bhOffset = pd.tseries.offsets.BusinessHour(offset = datetime.timedelta(days = 3, hours = 3))
แสดงออฟเซ็ตชั่วโมงทำการ -
print("\nBusinessHour Offset...\n",bhOffset) ตั้งค่าอ็อบเจ็กต์ประทับเวลาใน Pandas -
timestamp = pd.Timestamp('2021-9-30 06:50:20')
แสดงวันทำการถัดไป -
print("\nThe next business day...\n",timestamp + bhOffset.next_bday) ตัวอย่าง
ต่อไปนี้เป็นรหัส -
import datetime
import pandas as pd
# Set the timestamp object in Pandas
timestamp = pd.Timestamp('2021-9-30 06:50:20')
# Display the Timestamp
print("Timestamp...\n",timestamp)
# Create the BusinessHour Offset
# BusinessHour is the DateOffset subclass
bhOffset = pd.tseries.offsets.BusinessHour(offset = datetime.timedelta(days = 3, hours = 3))
# Display the BusinessHour Offset
print("\nBusinessHour Offset...\n",bhOffset)
# Display the next business day
print("\nThe next business day...\n",timestamp + bhOffset.next_bday) ผลลัพธ์
สิ่งนี้จะสร้างรหัสต่อไปนี้ -
Timestamp... 2021-09-30 06:50:20 BusinessHour Offset... <BusinessHour: offset=datetime.timedelta(days=3, seconds=10800): BH=09:00-17:00> The next business day... 2021-10-01 06:50:20