Skip to content
Related Articles

Related Articles

Python | Pandas Timedelta.seconds
  • Last Updated : 14 Jan, 2019
GeeksforGeeks - Summer Carnival Banner

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 in a similar manner. 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 Number of seconds.

Syntax: Timedelta.seconds

Parameters: None

Returns: return the Number of seconds.



Code #1:




# 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

Code #2:




# 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

Code #3:




# 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

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :