टाइमडेल्टा को नम्पी timedelta64 में बदलने के लिए, timedelta.to_timedelta64() मेथड का उपयोग करें।
सबसे पहले, आवश्यक लाइब्रेरी इंपोर्ट करें:
import pandas as pd
एक टाइमडेल्टा ऑब्जेक्ट बनाएं:
timedelta = pd.Timedelta('2 days 11 hours 22 min 25 s 50 ms 45 ns')
टाइमडेल्टा प्रदर्शित करें:
print("Timedelta...\n", timedelta)
टाइमडेल्टा को नम्पी timedelta64 में बदलें:
timedelta.to_timedelta64()
उदाहरण
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)
# Convert the Timedelta to a NumPy timedelta64.
res = timedelta.to_timedelta64()
# Return the result
print("\nConverting the Timedelta to a NumPy timedelta64....\n", res)
आउटपुट
Timedelta... 2 days 11:22:25.050000045 Converting the Timedelta to a NumPy timedelta64.... 213745050000045 nanoseconds