Timedelta অবজেক্টকে নির্দিষ্ট রেজোলিউশনে রাউন্ড করতে timedelta.round(freq='D') ব্যবহার করুন। freq='D' দিয়ে দৈনিক (daily) ফ্রিকোয়েন্সি সেট করা হয়।
প্রয়োজনীয় লাইব্রেরি ইমপোর্ট করুন
import pandas as pd
Timedelta অবজেক্ট তৈরি করুন
timedelta = pd.Timedelta('2 days 11 hours 22 min 25 s 50 ms 45 ns')
Timedelta প্রদর্শন করুন
print("Timedelta...\n", timedelta)
দৈনিক ফ্রিকোয়েন্সিতে রাউন্ড করুন
timedelta.round(freq='D')
সম্পূর্ণ উদাহরণ
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 11 hours 22 min 25 s 50 ms 45 ns')
# display the Timedelta
print("Timedelta...\n", timedelta)
# return the rounded Timestamp with daily frequency
# Here, the specified resolution is set using the "freq" parameter
res = timedelta.round(freq='D')
# display the rounded Timestamp
print("\nTimedelta (daily rounded)...\n", res)
আউটপুট
Timedelta... 2 days 11:22:25.050000045
Timedelta (daily rounded)... 2 days 00:00:00
ব্যাখ্যা: ১১ ঘন্টা ২২ মিনিট ২৫ সেকেন্ড >= ১২ ঘন্টা নয়, তাই নিকটতম দিন হলো ২ দিন (রাত ১২টা)। যদি ১২ ঘন্টার বেশি হতো, তবে ৩ দিন হতো।