Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to drop the index column while writing the DataFrame in a .csv file in Pandas? [duplicate]

My DataFrame contains two columns named 'a','b'. Now when I created a csv file of this DataFrame:

df.to_csv('myData.csv')

And when I opened this in an excel file, there is an extra column with indices that appears alongside the columns 'a' and 'b', but I don't want that. I only want columns 'a' and 'b' to appear in the excel sheet.

Is there any way to do this?

like image 652
aroma Avatar asked Dec 02 '16 14:12

aroma


1 Answers

Try,

 df.to_csv('myData.csv',index=False)
like image 127
Aakash Makwana Avatar answered Oct 17 '22 01:10

Aakash Makwana