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?

0

1 Answer 1

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')
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.