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

Python Pandas - ตรวจสอบว่า CustomBusinessHour เป็น Anchored หรือไม่

ใช้ CustomBusinessHour.is_anchored() ใน Pandas เพื่อตรวจสอบว่า CustomBusinessHour offset เป็น anchored (มีความถี่คงที่) หรือไม่

ขั้นตอน

  1. import pandas as pd
  2. สร้าง timestamp และ CustomBusinessHour offset
  3. เรียก cbhOffset.is_anchored()

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

import pandas as pd

timestamp = pd.Timestamp('2021-11-14 05:20:30')
cbhOffset = pd.tseries.offsets.CustomBusinessHour(start="09:30", end="18:30")

print("Timestamp...\n", timestamp)
print("\nCustomBusinessHour Offset...\n", cbhOffset)
print("\nUpdated Timestamp...\n", timestamp + cbhOffset)
print("\nCheck whether the CustomBusinessHour is anchored...\n", cbhOffset.is_anchored())

ผลลัพธ์

Timestamp... 2021-11-14 05:20:30
CustomBusinessHour Offset... 
Updated Timestamp... 2021-11-15 10:30:00
Check whether the CustomBusinessHour is anchored... True