Timedelta অবজেক্টকে ঘণ্টা রেজোলিউশনে রাউন্ড করতে timedelta.round(freq='H') ব্যবহার করুন। 'H' ঘণ্টা (hourly) নির্দেশ করে।
প্রয়োজনীয় লাইব্রেরি ইমপোর্ট করুন
import pandas as pd
Timedelta অবজেক্ট তৈরি করুন
timedelta = pd.Timedelta('2 days 10 hours 45 min 20 s 35 ms 55 ns')
Timedelta প্রদর্শন করুন
print("Timedelta...\n", timedelta)
ঘণ্টা ফ্রিকোয়েন্সিতে রাউন্ড করুন
timedelta.round(freq='H')
সম্পূর্ণ উদাহরণ
import pandas as pd
# TimeDeltas is Python's standard datetime library uses a different representation timedelta's
# create a Timedelta object
timedelta = pd.Timedelta('2 days 10 hours 45 min 20 s 35 ms 55 ns')
# display the Timedelta
print("Timedelta...\n", timedelta)
# return the rounded Timestamp with hourly frequency
# Here, the specified resolution is set using the "freq" parameter
res = timedelta.round(freq='H')
# display the rounded Timestamp
print("\nTimedelta (hourly rounded)...\n", res)
আউটপুট
Timedelta... 2 days 10:45:20.035000055
Timedelta (hourly rounded)... 2 days 11:00:00
ব্যাখ্যা: ৪৫ মিনিট ২০ সেকেন্ড >= ৩০ মিনিট, তাই রাউন্ড আপ হয়ে ১১ ঘণ্টা হয়েছে।