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

Python Pandas - คืนค่ารหัสกฎ (Rule Code) ที่ใช้กับ BusinessHour Object

เพื่อคืนค่ารหัสกฎ (rule code) ที่ใช้กับ BusinessHour object ให้ใช้คุณสมบัติ BusinessHour.rule_code ใน Pandas

ขั้นตอนตัวอย่าง

import pandas as pd

# สร้าง Timestamp
timestamp = pd.Timestamp('2021-1-1 01:55:30')
print("Timestamp...\n", timestamp)

# สร้าง BusinessHour Offset
bhOffset = pd.tseries.offsets.BusinessHour(start="09:30", end="18:00")

print("\nBusinessHour Offset...\n", bhOffset)
print("\nTimestamp ที่อัปเดต...\n", timestamp + bhOffset)
print("\nรหัสกฎของ BusinessHour object...\n", bhOffset.rule_code)

โค้ดเต็มและผลลัพธ์

import pandas as pd

timestamp = pd.Timestamp('2021-1-1 01:55:30')
print("Timestamp...\n", timestamp)

bhOffset = pd.tseries.offsets.BusinessHour(start="09:30", end="18:00")
print("\nBusinessHour Offset...\n", bhOffset)
print("\nTimestamp ที่อัปเดต...\n", timestamp + bhOffset)
print("\nรหัสกฎของ BusinessHour object...\n", bhOffset.rule_code)
Timestamp...
 2021-01-01 01:55:30
BusinessHour Offset...
 
Timestamp ที่อัปเดต...
 2021-01-01 10:30:00
รหัสกฎของ BusinessHour object...
 BH