Sarah
Sarah

Reputation: 617

How can I convert year, date, month to datetime?

For example, I have a column with data such as:

17.14.11
17.15.10
18.21.06

which is 2017-11-14, and I'd like to change this to a DateTime object such as:

2017-11-14
2017-10-15
2018-06-21

I tried to use pd.to_datetime but I think it doesn't recognize the above as a date. How can I convert this using pandas' to_datetime function?

Upvotes: 3

Views: 231

Answers (1)

BENY
BENY

Reputation: 323226

Check with format and to_datetime

pd.to_datetime(df['col'], format='%y.%d.%m')

Upvotes: 4

Related Questions