Categories
Python Answers

How to convert string to datetime format in Pandas Python?

Spread the love

Sometimes, we want to convert string to datetime format in Pandas Python.

In this article, we’ll look at how to convert string to datetime format in Pandas Python.

How to convert string to datetime format in Pandas Python?

To convert string to datetime format in Pandas Python, we can use the astype method.

For instance, we write

updated_df = df['timestamp'].astype('datetime64[ns]')

to get the timestamp column with df['timestamp'].

Then we call astype with 'datetime64[ns]' to convert the timestamp column values to datetimes.

Conclusion

To convert string to datetime format in Pandas Python, we can use the astype method.

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 *