MEhsan MEhsan -5 years ago 177
Python Question

How to Format a Date Column in Pandas?

I have a dataframe

that look like this:

ID Date
0 1 2008-01-24
1 2 2007-02-17

The format of

How can I format the dates to

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?

Answer Source

Use the .dt accessor:

df["Date"] = df["Date"].dt.strftime("%m-%d-%Y")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download