简体   繁体   中英

How to put the dates in chronological order in python CSV

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

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"])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM