CustomBusinessHour 오프셋 개체에서 사용자 지정 업무 시간의 종료 시간을 24시간 형식으로 표시하려면 Pandas의 CustomBusinessHour.end 속성을 사용하세요.
먼저 필요한 라이브러리를 가져옵니다 -
import pandas as pd
Pandas에서 타임스탬프 개체 설정 -
timestamp = pd.Timestamp('2021-11-14 05:20:30')
CustomBusinessHour 오프셋을 만듭니다. 여기에서 "시작"은 24시간 형식의 사용자 지정 업무 시간의 시작 시간입니다. "종료"는 24시간 형식의 사용자 지정 업무 시간의 종료 시간입니다. -
cbhOffset = pd.tseries.offsets.CustomBusinessHour(start="09:30", end = "18:30", n = 5)
타임스탬프에 오프셋을 추가하고 업데이트된 타임스탬프 표시 -
print("\nUpdated Timestamp...\n",timestamp + cbhOffset)
사용자 지정 업무 시간의 종료 시간 표시 -
print("\nThe end time of the custom business hour...\n",cbhOffset.end) 예시
다음은 코드입니다 -
import pandas as pd
# Set the timestamp object in Pandas
timestamp = pd.Timestamp('2021-11-14 05:20:30')
# Display the Timestamp
print("Timestamp...\n",timestamp)
# Create the CustomBusinessHour Offset
# CustomBusinessHour is the DateOffset subclass
# Here, "start" is the start time of your custom business hour in 24h format.
# The "end" is the end time of your custom business hour in 24h format.
cbhOffset = pd.tseries.offsets.CustomBusinessHour(start="09:30", end = "18:30", n = 5)
# Display the CustomBusinessHour Offset
print("\nCustomBusinessHour Offset...\n",cbhOffset)
# Add the offset to the Timestamp and display the Updated Timestamp
print("\nUpdated Timestamp...\n",timestamp + cbhOffset)
# Display the end time of the custom business hour
print("\nThe end time of the custom business hour...\n",cbhOffset.end) 출력
이것은 다음 코드를 생성합니다 -
Timestamp... 2021-11-14 05:20:30 CustomBusinessHour Offset... <5 * CustomBusinessHours: CBH=09:30-18:30> Updated Timestamp... 2021-11-15 14:30:00 The end time of the custom business hour... (datetime.time(18, 30),)