Pandas Timedelta.seconds Examples
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) |
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) |
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) |
0 days 00:02:13 133
Python | Pandas Timedelta.seconds
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.