问题描述:

I have a dataframe df that look like this:

 ID Date

0 1 2008-01-24

1 2 2007-02-17

The format of Date is %Y-%m-%d

How can I format the dates to %m-%d-%Y format?

I tried using this syntax but it did not give the right format:

df["Date"] = df["Date"].strftime("%m-%d-%Y")

Any idea how to solve this?

网友答案:

Use the .dt accessor:

df["Date"] = df["Date"].dt.strftime("%m-%d-%Y")
相关阅读:
Top