0

One df have one column date which has the following format:

0         2019/5/20 22:49:29
1         2019/5/20 23:18:23
2           2019/3/8 9:11:35
3           2019/3/8 9:19:58
4         2019/5/20 22:57:12
5           2019/3/8 9:06:41

How can I convert it to format six digits year.month.day format? I have tried with the following code to but only get year-month-day:

df['date'] = pd.to_datetime(df['date']).dt.date

But my desired output:

0         19.05.20
1         19.05.20
2         19.03.08
3         19.03.08
4         19.05.20
5         19.03.08

Thank you.

0

1 Answer 1

2

If you want strings:

df['date'] = df['date'].dt.strftime('%y.%m.%d')

# if your date is not datetime type:
# df['date'] = pd.to_datetime(df['date']).dt.strftime('%y.%m.%d')
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.