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

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

ใช้ property CustomBusinessHour.n เพื่อคืนจำนวนการเพิ่ม (increments) ที่นำไปใช้กับ CustomBusinessHour offset

ขั้นตอน

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

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

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 count of increments on the CustomBusinessHour object..\n", cbhOffset.n)

ผลลัพธ์

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 count of increments on the CustomBusinessHour object.. 7