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

Python Pandas - คืนรหัสกติกาของ CustomBusinessDay object

ใช้ property CustomBusinessDay.rule_code เพื่อคืนรหัสกติกา (rule code) ของความถี่ที่ใช้กับ CustomBusinessDay offset

ขั้นตอน

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

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

import pandas as pd

timestamp = pd.Timestamp('2021-10-22 03:10:35')
cbdOffset = pd.tseries.offsets.CustomBusinessDay(n=2, 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 rule code of the CustomBusinessDay object..\n", cbdOffset.rule_code)

ผลลัพธ์

Timestamp... 2021-10-22 03:10:35
CustomBusinessDay Offset... <2 * CustomBusinessDays>
Updated Timestamp... 2021-10-26 03:10:35
Frequency applied on the given CustomBusinessDay Offset object... 2C
The rule code of the CustomBusinessDay object.. C