Python Forum

Full Version: How to define index column name using df.to_csv
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,
I have dataframe, and I want to write to csv. But when write to csv, the first column name disaaper (which is Index)

Before write,
Index c1 c2
A 2 5
B 5 9

I use below command,
summary_table.to_csv('outsummary2.csv',index=True,header=True)
when I open csv file, data look like:

       c1 c2
A      2  5
B      5  9
how can rename the index column name? to look like my data:

Names c1 c2
A      2  5
B      5  9