Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
in Python by (16.4k points)

Look at the first row of my DateTime column (Below line), 

Mon Nov 02 20:37:10 GMT+00:00 2015

Right now, This Datetime column is an object and I need to convert them to DateTime format so that I can able to get my date as something like this 1998-08-11 and I will create a separate column for time.

This is the code, that I'm using to convert column to date format :

for item, frame in df['DateTime'].iteritems():

     datetime.datetime.strptime(df['DateTime'], "%a-%b-%d-%H-%M-%S-%Z-%Y")

But, in the end, I'm getting this kind of error:

TypeError: must be str, not Series

Anyone Please help me?

Thank you :)

1 Answer

0 votes
by (26.4k points)

You can use, pd.to_datetime(): 

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


pd.to_datetime('Mon Nov 02 20:37:10 GMT+00:00 2015')

It produces

Timestamp('2015-11-02 20:37:10')

Want to learn more topics related to Python? Come and Join: Python certification course

Browse Categories