Stack Overflow Asked by user13930292 on November 24, 2021
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
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.
Answered by Youyoun on November 24, 2021
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')
Answered by Chris on November 24, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP