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)
Answer from Nilani Algiriyage on Stack Overflowpython - How to avoid pandas creating an index in a saved csv - Stack Overflow
pandas: remove column index only
Pandas copy series with no header, no index, commas seperated
What is this index column in pandas and why do I get an Unnamed: 0 error?
Videos
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)
Figured out a way to do this:
df.to_csv('filename.csv', header = False)
This tells pandas to write a csv file without the header. You can do the same with df.to_excel.
Use index=False.
Copydf.to_csv('your.csv', index=False)
There are two ways to handle the situation where we do not want the index to be stored in csv file.
As others have stated you can use index=False while saving your
dataframe to csv file.df.to_csv('file_name.csv',index=False)- Or you can save your dataframe as it is with an index, and while reading you just drop the column unnamed 0 containing your previous index.Simple!
df.to_csv(' file_name.csv ')
df_new = pd.read_csv('file_name.csv').drop(['unnamed 0'],axis=1)