หากต้องการคืนค่าจำนวนที่เพิ่มขึ้นที่ใช้กับออฟเซ็ต BusinessDay ให้ใช้คุณสมบัติ BusinessDay.n ใน Pandas
ขั้นแรก นำเข้าไลบรารีที่จำเป็น -
import datetime import pandas as pd
ตั้งค่าอ็อบเจ็กต์ประทับเวลาใน Pandas” −
timestamp = pd.Timestamp('2021-10-30 01:55:02.000045')
สร้างออฟเซ็ตวันธุรกิจ BusinessDay เป็นคลาสย่อย DateOffset -
bdOffset = pd.tseries.offsets.BusinessDay(n = 6)
แสดงการประทับเวลาที่อัปเดต -
print("\nUpdated Timestamp...\n",timestamp + bdOffset)
ส่งกลับจำนวนที่เพิ่มขึ้นในวัตถุ BusinessDay ที่กำหนด -
print("\nThe count of increments on the BusinessDay object..\n", bdOffset.n) ตัวอย่าง
ต่อไปนี้เป็นรหัส -
import datetime
import pandas as pd
# Set the timestamp object in Pandas
timestamp = pd.Timestamp('2021-10-30 01:55:02.000045')
# Display the Timestamp
print("Timestamp...\n",timestamp)
# Create the BusinessDay Offset
# BusinessDay is the DateOffset subclass
bdOffset = pd.tseries.offsets.BusinessDay(n = 6)
# Display the BusinessDay Offset
print("\nBusinessDay Offset...\n",bdOffset)
# Display the Updated Timestamp
print("\nUpdated Timestamp...\n",timestamp + bdOffset)
# return the frequency applied on the given BusinessDay object as a string
print("\nFrequency on the given BusinessDay Offset...\n",bdOffset.freqstr)
# return the count of increments on the given BusinessDay object
print("\nThe count of increments on the BusinessDay object..\n", bdOffset.n) ผลลัพธ์
สิ่งนี้จะสร้างรหัสต่อไปนี้ -
Timestamp... 2021-10-30 01:55:02.000045 BusinessDay Offset... <6 * BusinessDays> Updated Timestamp... 2021-11-08 01:55:02.000045 Frequency on the given BusinessDay Offset... 6B The count of increments on the BusinessDay object.. 6