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

2 Answers2

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')
Chris
  • 15,819
  • 3
  • 24
  • 37
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.

Youyoun
  • 338
  • 1
  • 5