Categories
Python Answers

How to convert between datetime, Timestamp and datetime64 in Python Pandas?

Spread the love

To convert between datetime, Timestamp and datetime64 in Python Pandas, we can use the Timestamp function.

For instance, we write

pd.Timestamp(numpy.datetime64('2012-05-01T01:00:00.000000'))

to call Timestamp on a NumPy datetime64 value.

We can use to_datetime to convert a date time string to a Pandas date time value.

For instance, we write

pd.to_datetime('2022-05-01T01:00:00.000000+0100')

to call pd.to_datetime with a date time string to return a Python datetime value from it.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *