Python | Panda Timestamp.to_datetime64

Pandas function Timestamp.to_datetime64() returns a numpy.datetime64 object with precision & # 39; ns & # 39; for a given Timestamp object.

Syntax: Timestamp.to_datetime64 ()

Parameters: None

Return: numpy.datetime64 object

Example # 1: Use the Timestamp.to_datetime64 () function to return a numpy.datetime64 object for a given Timestamp object.

Output:

We will now use the Timestamp.to_datetime64 () function to return a numpy.datetime64 object for a given timestamp.

# import pandas as pd

import pandas as pd

 
# Create Timestamp object

ts = pd.Timestamp (year = 2011 , month = 11 , day = 21

hour = 10 , second = 49 , tz = 'US / Central'

  
# Print Timestamp object

print (ts)

# return object numpy.datetime64
ts.to_datetime64 ()

Output:

As we can see from the output, the Timestamp.to_datetime64 () function returned a numpy.datetime64 object for the given Timestamp object with ns precision.

Example # 2: Use the Timestamp.to_datetime64 () to return a numpy.datetime64 object for a given Timestamp object.

Output:

We will now use the Timestamp.to_datetime64 () function to return a numpy.datetime64 object for a given timestamp.

# import pandas as pd

import pandas as pd

 
# Create Timestamp object

ts = pd.Timestamp (year = 2009 , month = 5 , day = 31

hour = 4 , second = 49 , tz = 'Europe / Berlin' )

  
# Print the Timestamp object

print ( ts)

# return a numpy.datetime64 object
ts.to_datetime64 ()

Output:

As we can see from the output, the Timestamp.to_datetime64 () function returned a numpy.datetime64 object for the given Timestamp object with ns precision.



Get Solution for free from DataCamp guru