How do you remove the column name row when exporting a pandas DataFrame?

cmgerber picture cmgerber · Nov 5, 2013 · Viewed 89.4k times · Source

Say I import the following Excel spreadsheet into a dataframe:

Val1 Val2 Val3
1     2    3 
5     6    7 
9     1    2

How do I delete the column name row (in this case Val1, Val2, Val3) so that I can export a csv with no column names, just the data?

I have tried df.drop() and df.ix[1:] and have not been successful with either.

Answer

Nilani Algiriyage picture Nilani Algiriyage · Nov 5, 2013

You can write to csv without the header using header=False and without the index using index=False. If desired, you also can modify the separator using sep.

CSV example with no header row, omitting the header row:

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

TSV (tab-separated) example, omitting the index column:

df.to_csv('filename.tsv', sep='\t', index=False)