How to avoid Python/Pandas creating an index in a saved csv?

Alexis picture Alexis · Dec 30, 2013 · Viewed 370.7k times · Source

I am trying to save a csv to a folder after making some edits to the file.

Every time I use pd.to_csv('C:/Path of file.csv') the csv file has a separate column of indexes. I want to avoid printing the index to csv.

I tried:

pd.read_csv('C:/Path to file to edit.csv', index_col = False)

And to save the file...

pd.to_csv('C:/Path to save edited file.csv', index_col = False)

However, I still got the unwanted index column. How can I avoid this when I save my files?

Answer

Probably rgbkrk picture Probably rgbkrk · Aug 10, 2014

Use index=False.

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