0

I have a column in my csv file that I want to have sorted by the datetime. It's in the format like 2020-10-06 03:28:00. I tried doing it like this but nothing seems to have happened.

df = pd.read_csv('data.csv')
df = df.sort_index()
df.to_csv('btc.csv', index= False)

I need to have that index= False in the .to_csv so that it is formatted properly for later so I can't remove that if that is causing an issue. The dtime is my first column in the csv file and the second column is a unix timestamp so I could also use that if it would work better.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
mbohde
  • 109
  • 1
  • 7

1 Answers1

0

sort_values(by=column_name) to sort pandas. DataFrame by the contents of a column named column_name . Before doing this, the data in the column must be converted to datetime if it is in another format using pandas. to_datetime(arg) with arg as the column of dates.

Bharath
  • 406
  • 2
  • 13