Get Seconds from timestamp (date) in pandas python

dt.second  is the inbuilt method to get seconds from timestamp (date) in Pandas Python.  Let’s see how to

  • Get the seconds from timestamp (date) in pandas python

First lets create the dataframe


import pandas as pd
import numpy as np
import datetime

date1 = pd.Series(pd.date_range('2012-1-1 11:20:00', periods=7, freq='s'))
df = pd.DataFrame(dict(date_given=date1))
print(df)

so the resultant dataframe will be

Get Seconds from timestamp in pandas python 1

 

Second function pandas:

second function gets seconds value of the timestamp

df['seconds_of_timestamp'] = df['date_given'].dt.second
print(df)

so the resultant dataframe will be

Get Seconds from timestamp in pandas python 2

 

Get Seconds from timestamp (date) in pandas python                                                                                                           Get Seconds from timestamp (date) in pandas python

Author

  • Sridhar Venkatachalam

    With close to 10 years on Experience in data science and machine learning Have extensively worked on programming languages like R, Python (Pandas), SAS, Pyspark.

    View all posts