1

I have a pandas dataframe with Date with the following formats:

Year-Month-Day

 2000-02-01  
 2000-02-02 
 2000-02-03 

I would like it to be like this:

Month/Day/Year

 02/01/2000  
 02/02/2000 
 02/03/2000 

Not only the parts of the date must be rearranged, but also the symbol "/" must separate the parts of the date.

How to do that with Python?

mad
  • 2,677
  • 8
  • 35
  • 78

1 Answers1

1

If values are strings use to_datetime with Series.dt.strftime, but then datetimes are converted to strings:

df['date'] = pd.to_datetime(df['date']).dt.strftime('%m/%d/%Y')
print (df)
         date
0  02/01/2000
1  02/02/2000
2  02/03/2000

If values are datetimes only use Series.dt.strftime:

df['date'] = df['date'].dt.strftime('%m/%d/%Y')
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252