0

have a df with values :

name      age 
 
mark    2002-12-19    
tom     2003-11-30

how to reorder the date format with dd mm yyyy

name      age 
 
mark    19-12-2002    
tom     30-11-2003

tried this How to change the datetime format in pandas

but it is storing as string. i need in date format

1
  • 1
    November doesn't have 31 days Commented Jul 22, 2020 at 13:15

2 Answers 2

1

Assuming your date stamps are valid, which your second one appears to not be.

df['age'] = pd.to_datetime(df['age']).dt.strftime('%d-%m-%Y')
Sign up to request clarification or add additional context in comments.

1 Comment

ValueError: invalid literal for int() with base 10: '30-07-2018'
0

df.loc[:, "age"] = pd.to_datetime(df["age"], format="%Y-%m-%d").dt.strftime("%d-%m-%Y")

you can then use .sort_values() to sort the dates as you wish.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.