Home > front end >  How to put the dates in chronological order in python CSV
How to put the dates in chronological order in python CSV

Time:12-16

So I am working on processing some data and after running my file, everything is fine except that the date are not in order. I used the code below to try putting them in order but didnt work. by the way 'updated_at' is the column I am trying to put in chronological

df = df.sort_values(by=["updated_at"], ascending=True)

Please let me know how I can make this work. I have attached a picture to for better understanding of my question.

"updated_at" column pic

CodePudding user response:

We are missing a bit of the context, but it could be that the column "updated_at" is not a datetime column, but a simple string, since it looks to me it is sorted alfabetically. Check with df["updated_at"].dtype and if it's not a datetime type (it will probably be of type "object") then do

df["update_at"] = pd.to_datetime(df["update_at"])
  • Related