Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 900
Alexis Avatar asked Dec 30 '13 18:12

Alexis


People also ask

How do I get rid of pandas indexing?

The most straightforward way to drop a Pandas dataframe index is to use the Pandas . reset_index() method. By default, the method will only reset the index, forcing values from 0 - len(df)-1 as the index. The method will also simply insert the dataframe index into a column in the dataframe.

How do I turn off auto index in pandas?

The explanation: Dataframes always have an index, and there is no way of how to remove it, because it is a core part of every dataframe. ( iloc[0:4]['col name'] is a dataframe, too.) You can only hide it in your output.

How do I remove the index and header from a data frame?

Just simply put header=False and for eliminating the index using index=False.


1 Answers

Use index=False.

df.to_csv('your.csv', index=False) 
like image 176
Probably rgbkrk Avatar answered Sep 28 '22 06:09

Probably rgbkrk