Edward
Edward

Reputation: 4623

Convert to datetime with different types of time format

I have a dataset like this

import pandas as pd
df = pd.DataFrame({'a' : ['30.09.2015', '13.10.2015 18:13:47' , '01.04.2012', '13.10.2015 18:25:36']})

I want to convert to time format

2015-09-30
2015-10-13

I tried to do different ways

pd.to_datetime(df['a'], format= '%d.%m.%Y %H:%M:%S')
pd.to_datetime(df['a'], format= '%d.%m.%Y')
pd.to_datetime(df['a'], format= c('%d.%m.%Y', '%d.%m.%Y %H:%M:%S'))

It's wrong. How to fix it?

Upvotes: 0

Views: 35

Answers (1)

John Zwinck
John Zwinck

Reputation: 249384

You've made it harder than it needed to be! Just do this:

pd.to_datetime(df['a'])

Upvotes: 1

Related Questions