Categories
Python Answers

How to convert DataFrame column type from string to datetime with Python Pandas?

Spread the love

To convert DataFrame column type from string to datetime with Python Pandas, we can use the to_datetime method.

For instance, we write

df['col'] = pd.to_datetime(df['col'])

to call to_datetime with df['col'] to covert the values in the col column to datetimes and assign them back to the col column.

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 *