Open In App

Python | Pandas Timedelta.seconds

Last Updated : 26 Dec, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages and makes importing and analyzing data much easier.

Timedelta is a subclass of datetime.timedelta, and behaves similarly. It is the Pandas equivalent of Python’s datetime.timedelta and is interchangeable with it in most cases. Timedelta.seconds property in pandas.Timedelta is used to return the number of seconds.

Python Pandas Timedelta.seconds Syntax

Syntax: Timedelta.seconds

Parameters: None

Returns: return the Number of seconds.

Pandas Timedelta.seconds Examples

Below are the examples by which we can create time deltas in Pandas in Python:

Working with Time deltas in Pandas

In this example, a Timedelta an object representing 3 days, 6 hours, 5 minutes, 1 second, and 111 nanoseconds is created using pandas. The object is then printed, followed by accessing and displaying its total seconds component.

Python3




# importing pandas as pd
import pandas as pd
 
# Create the Timedelta object
td = pd.Timedelta('3 days 06:05:01.000000111')
 
# Print the Timedelta object
print(td)
 
print(td.seconds)


Output

3 days 06:05:01.000000
21901

Manipulating and Accessing Components of Pandas Timedelta

In this example, a Timedelta object is initialized to represent a duration of 7 days, 15 minutes, and 3 seconds using pandas. The object is printed, and its total seconds component is subsequently displayed.

Python3




# importing pandas as pd
import pandas as pd
 
# Create the Timedelta object
td = pd.Timedelta('7 days 15 min 3 s')
 
# Print the Timedelta object
print(td)
 
print(td.seconds)


Output

7 days 00:15:03
903

Creating and Accessing Pandas Timedelta with Specified Units

In this example, a Timedelta object is instantiated with a duration of 133 seconds using the Pandas library, specifying the unit as seconds. The object is then printed, and its total seconds value is retrieved and displayed.

Python3




# importing pandas as pd
import pandas as pd
import datetime
 
# Create the Timedelta object
td = pd.Timedelta(133, unit='s')
 
# Print the Timedelta object
print(td)
 
print(td.seconds)


Output

0 days 00:02:13
133



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads