Python Forum
How to define index column name using df.to_csv
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to define index column name using df.to_csv
#1
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
Reply


Messages In This Thread
How to define index column name using df.to_csv - by SriRajesh - Feb-13-2020, 03:45 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  df.to_csv('saved_data.csv') Led_Zeppelin 1 1,099 Sep-11-2022, 12:29 AM
Last Post: deanhystad
  Removing the index column from df bnadir55 7 2,926 Apr-05-2022, 02:49 PM
Last Post: snippsat
  pandas pivot table: How to find count for each group in Index and Column JaneTan 0 3,226 Oct-23-2021, 04:35 AM
Last Post: JaneTan
  Index error - columns vs non-column Vinny 3 4,848 Aug-09-2021, 04:46 PM
Last Post: snippsat
Lightbulb 'str' object has no attribute 'to_csv' brunolelli 3 13,041 Mar-25-2021, 06:40 AM
Last Post: ndc85430
  how to retain time format in df.to_csv Mekala 2 3,069 Aug-07-2020, 07:04 AM
Last Post: buran
  How get row index of matching row in column 0 Sri 7 3,585 Apr-10-2019, 08:26 PM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020