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

Python Pandas - ดึง weekmask ของ CustomBusinessDay offset

ใช้ property CustomBusinessDay.weekmask เพื่อดึง weekmask ที่ใช้กับ CustomBusinessDay offset

ขั้นตอน

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

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

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)
print("\nThe weekmask on the CustomBusinessDay object..\n", cbdOffset.weekmask)

ผลลัพธ์

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
The weekmask on the CustomBusinessDay object.. Mon Tue Wed Fri