YasserKhalil
YasserKhalil

Reputation: 9538

Remove index column from DataFrame Pandas

I have searched a lot about this topic of how to remove the index column of the datframe when exporting the dataframe to csv file. I found many solutions and tricks but none of them worked with me. In the csv output I got 0 (the column index) at the first row of the CSV output. Can you guide me of fixing such a problem?!!

Upvotes: 0

Views: 1771

Answers (2)

Flavio Moraes
Flavio Moraes

Reputation: 1351

Are you using pandas? If so, you can use the .to_csv method with the argument index=False to remove index:

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

or header=False to remove column names:

df.to_csv('output.csv', header=False)

Upvotes: 1

Prakriti Shaurya
Prakriti Shaurya

Reputation: 197

   df.to_csv('output.csv', index=False, header=False)

Upvotes: 1

Related Questions