Python Pandas - Return the microseconds from Timedelta object


To return the microseconds 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. Create a Timedelta object

timedelta = pd.Timedelta('7 days 20 min 15 s 35 ms')

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
# create a Timedelta object
timedelta = pd.Timedelta('7 days 20 min 15 s 35 ms')

# 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...
 7 days 00:20:15.035000

Timedelta (microseconds value)...
 35000

Updated on: 13-Oct-2021

132 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements