18

I am writing to a .csv file with:

my_data_frame.to_cav("some_path")

When trying to read the file with:

pd.read_csv("some_path")

I can tell that an unnamed column was added. How can i fix that?

avicohen
  • 2,547
  • 5
  • 15
  • 16

1 Answers1

36

to_csv() writes an index per default, so you can either disable index when saving your CSV:

df.to_csv('file.csv', index=False)

or specify an index column when reading:

df = pd.read_csv('file.csv', index_col=0)
MaxU - stop genocide of UA
  • 191,778
  • 30
  • 340
  • 375