Pandas - Convert a Timestamp object to a native Python datetime object


To convert a Timestamp object to a native Python datetime object, use the timestamp.to_pydatetime() method.

At first, import the required libraries −

import pandas as pd

Create the timestamp object in Pandas

timestamp = pd.Timestamp('2021-09-11T13:12:34.261811')

Convert timestamp to native Python datetime object

timestamp.to_pydatetime()

Example

Following is the code

import pandas as pd

# set the timestamp object in Pandas
timestamp = pd.Timestamp('2021-09-11T13:12:34.261811')

# display the Timestamp
print("Timestamp...\n", timestamp)

# convert timestamp to native Python datetime object
print("\nConvert Timestamp...\n", timestamp.to_pydatetime())

Output

This will produce the following code

Timestamp...
 2021-09-11 13:12:34.261811
Convert Timestamp...
 2021-09-11 13:12:34.261811

Updated on: 13-Oct-2021

9K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements