निर्दिष्ट रिज़ॉल्यूशन के साथ टाइमडेल्टा को राउंड करने के लिए, timestamp.round() मेथड का उपयोग करें। freq पैरामीटर का उपयोग करके रिज़ॉल्यूशन सेट करें।
सबसे पहले, आवश्यक लाइब्रेरी इंपोर्ट करें:
import pandas as pd
एक टाइमडेल्टा ऑब्जेक्ट बनाएं:
timedelta = pd.Timedelta('2 days 10 hours 45 min 20 s 35 ms 55 ns')
टाइमडेल्टा प्रदर्शित करें:
print("Timedelta...\n", timedelta)
सेकंड फ्रीक्वेंसी के साथ राउंडेड टाइमस्टैम्प लौटाएं। यहां, निर्दिष्ट रिज़ॉल्यूशन "freq" पैरामीटर का उपयोग करके सेट किया गया है:
timedelta.round(freq='s')
उदाहरण
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 seconds frequency
# Here, the specified resolution is set using the "freq" parameter
res = timedelta.round(freq='s')
# display the rounded Timestamp
print("\nTimedelta (seconds rounded)...\n", res)
आउटपुट
Timedelta... 2 days 10:45:20.035000055 Timedelta (seconds rounded)... 2 days 10:45:20