Get nano seconds from timestamp in pandas python

dt.nanosecond  is the inbuilt method to get nano seconds from timestamp in Pandas Python.  Let’s see how to

  • Get the nano seconds from timestamp 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:50', periods=7, freq='ns'))
df = pd.DataFrame(dict(date_given=date1))
print(df)

so the resultant dataframe will be

 

Nanosecond function in pandas:

nanosecond function gets nanoseconds value from the timestamp


df['nanoseconds_of_timestamp'] = df['date_given'].dt.nanosecond
print(df)

so the resultant dataframe will be

 

Get nano seconds from timestamp in pandas python p                                                                                                           Get nano seconds from timestamp 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