To return the nanoseconds from Timedelta object, use the timedelta.microseconds property. At first, import the required libraries −
import pandas as pd
TimeDeltas is Python’s standard datetime library uses a different representation timedelta’s. Set integer input for microseconds using unit 'us'. Create a Timedelta object
timedelta = pd.Timedelta(55, unit ='us')
Display the Timedelta
print("Timedelta...\n", timedelta)Return the microseconds value
timedelta.microseconds
Example
Following is the code
import pandas as pd
# TimeDeltas is Python’s standard datetime library uses a different representation timedelta’s
# set integer input for microseconds using unit 'us'
# create a Timedelta object
timedelta = pd.Timedelta(55, unit ='us')
# display the Timedelta
print("Timedelta...\n", timedelta)
# return the microseconds value
res = timedelta.microseconds
# display the microseconds
print("\nTimedelta (microseconds value)...\n", res)Output
This will produce the following code
Timedelta... 0 days 00:00:00.055000 Timedelta (microseconds value)... 55