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

Python Pandas - คืนจำนวนการเพิ่มของ CustomBusinessDay offset

ใช้ property CustomBusinessDay.n เพื่อคืนจำนวนการเพิ่ม (increments) ของ CustomBusinessDay offset

ขั้นตอน

  1. import pandas as pd
  2. สร้าง timestamp และ CustomBusinessDay offset
  3. เข้าถึง cbdOffset.n

ตัวอย่างโค้ด

import pandas as pd

timestamp = pd.Timestamp('2021-10-22 03:10:35')
cbdOffset = pd.tseries.offsets.CustomBusinessDay(n=4, weekmask='Mon Tue Wed Fri')

print("Timestamp...\n", timestamp)
print("\nCustomBusinessDay Offset...\n", cbdOffset)
print("\nUpdated Timestamp...\n", timestamp + cbdOffset)
print("\nFrequency applied on the given CustomBusinessDay Offset object...\n", cbdOffset.freqstr)
print("\nThe count of increments on the CustomBusinessDay object..\n", cbdOffset.n)

ผลลัพธ์

Timestamp... 2021-10-22 03:10:35
CustomBusinessDay Offset... <4 * CustomBusinessDays>
Updated Timestamp... 2021-10-29 03:10:35
Frequency applied on the given CustomBusinessDay Offset object... 4C
The count of increments on the CustomBusinessDay object.. 4