19

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,897
  • 6
  • 16
  • 16

1 Answers1

39

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 - stand with Ukraine
  • 205,989
  • 36
  • 386
  • 419