Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (17.6k points)

I have a Pandas data frame, one of the columns of which contains date strings in the format 'YYYY-MM-DD' e.g. '2013-10-28'.

At the moment the dtype of the column is 'object'.

How do I convert the column values to Pandas date format?

1 Answer

0 votes
by (41.4k points)

Use astype:

In [31]: df

Out[31]: 

   a        time

0  1  2013-01-01

1  2  2013-01-02

2  3  2013-01-03

In [32]: df['time'] = df['time'].astype('datetime64[ns]')

In [33]: df

Out[33]: 

   a                time

0  1 2013-01-01 00:00:00

1  2 2013-01-02 00:00:00

2  3 2013-01-03 00:00:00

If you want to learn more about Pandas then visit this Python Course designed by the industrial experts.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jul 3, 2019 in Python by Sammy (47.6k points)

Browse Categories

...