How to drop the index column while writing the DataFrame in a .csv file in Pandas?
11,264
Try,
df.to_csv('myData.csv',index=False)
Related videos on Youtube
Comments
-
aroma over 1 year
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?
-
Tropicalrambler about 4 yearsExtremely simple and elegant solution to someone who is no longer ignorant about it. Works like a charm. Using it in combination with xlsxwriter
df.to_excel(writer, sheet_name='Data', index=False)