Python | Pandas Timedelta.seconds
Last Updated :
26 Dec, 2023
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
import pandas as pd
td = pd.Timedelta( '3 days 06:05:01.000000111' )
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
import pandas as pd
td = pd.Timedelta( '7 days 15 min 3 s' )
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
import pandas as pd
import datetime
td = pd.Timedelta( 133 , unit = 's' )
print (td)
print (td.seconds)
|
Output
0 days 00:02:13
133
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...