কাস্টম বিজনেস আওয়ার অফসেট অবজেক্ট থেকে 24 ঘন্টা ফরম্যাটে কাস্টম ব্যবসার সময়ের শেষ সময় প্রদর্শন করতে, পান্ডাসে CustomBusinessHour.end প্রপার্টি ব্যবহার করুন।
প্রথমে, প্রয়োজনীয় লাইব্রেরিগুলি আমদানি করুন -
import pandas as pd
পান্ডাস-
-এ টাইমস্ট্যাম্প অবজেক্ট সেট করুনtimestamp = pd.Timestamp('2021-11-14 05:20:30')
কাস্টম বিজনেস আওয়ার অফসেট তৈরি করুন। এখানে, "শুরু" হল 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),)