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)
Share:
11,264

Related videos on Youtube

aroma
Author by

aroma

Just a nigga, tryna code.

Updated on September 16, 2022

Comments

  • aroma
    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
    Tropicalrambler about 4 years
    Extremely 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)