To return a components namedtuple-like, use the timedelta.components. 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('1 days 10 min 20 s')
Return a components namedtuple-like
timedelta.components
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('1 days 10 min 20 s') # display the Timedelta print("Timedelta...\n", timedelta) # return a components namedtuple-like res = timedelta.components # display the component print("\nComponent...\n", res)
Output
This will produce the following code
Timedelta... 1 days 00:10:20 Component... Components(days=1, hours=0, minutes=10, seconds=20, milliseconds=0, microseconds=0, nanoseconds=0)