
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python Pandas - Get the Total seconds in the duration from the Timedelta object
To get the Total seconds in the duration from the Timedelta object, use the timedelta.total_seconds() method.
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('2 days 11 hours 22 min 25 s 50 ms 45 ns')
Display the Timedelta −
print("Timedelta...\n", timedelta)
Get the total seconds −
timedelta.total_seconds()
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('2 days 11 hours 22 min 25 s 50 ms 45 ns') # display the Timedelta print("Timedelta...\n", timedelta) # get the total seconds res = timedelta.total_seconds() # Return the result i.e. the total seconds in the duration print("\nTotal seconds...\n", res)
Output
This will produce the following code −
Timedelta... 2 days 11:22:25.050000045 Total seconds... 213745.05
- Related Articles
- Python Pandas - Get the seconds from Timedelta object using integer input
- Python Pandas - Get the seconds from Timedelta object using string input
- Python Pandas - Return the seconds from Timedelta object
- Python Pandas - Return the microseconds from Timedelta object
- Python Pandas - Return the nanoseconds from Timedelta object
- Python Pandas - Get the seconds of the period from the PeriodIndex object
- Python Pandas - Round the Timedelta with seconds frequency
- Python Pandas - Get the number of days from TimeDelta
- Python Pandas - Return the nanoseconds from Timedelta object using integer input
- Python Pandas - Return the nanoseconds from Timedelta object using string input
- Python Pandas - Return the microseconds from Timedelta object using integer input
- Python Pandas - Return the microseconds from Timedelta object using string input
- Python Pandas - Return the maximum value of the Timedelta object
- Python Pandas - Return the minimum value of the Timedelta object
- Convert a pandas Timedelta object into a Python timedelta object

Advertisements