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

Python Pandas - ดึง weekmask ที่ใช้กับ CustomBusinessHour offset

ใช้ property CustomBusinessHour.weekmask เพื่อดึง weekmask (วันที่ทำการ) ที่กำหนดให้กับ CustomBusinessHour offset

ขั้นตอน

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

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

import pandas as pd

timestamp = pd.Timestamp('2021-11-14 05:20:30')
cbhOffset = pd.tseries.offsets.CustomBusinessHour(n=7, weekmask='Mon Tue Wed Fri')

print("Timestamp...\n", timestamp)
print("\nCustomBusinessHour Offset...\n", cbhOffset)
print("\nUpdated Timestamp...\n", timestamp + cbhOffset)
print("\nFrequency applied on the given CustomBusinessHour Offset object...\n", cbhOffset.freqstr)
print("\nThe weekmask on the CustomBusinessHour object..\n", cbhOffset.weekmask)

ผลลัพธ์

Timestamp... 2021-11-14 05:20:30
CustomBusinessHour Offset... <7 * CustomBusinessHours: CBH=09:00-17:00>
Updated Timestamp... 2021-11-15 16:00:00
Frequency applied on the given CustomBusinessHour Offset object... 7CBH
The weekmask on the CustomBusinessHour object.. Mon Tue Wed Fri