Python Forum
Insert header at first row, for existing csv
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Insert header at first row, for existing csv
#1
Hi Team,

I have input data in csv file like below.

1,EAST,100
2,WEST,200
3,SOUTH,300
4,NORTH,400


I want to add these headers to above input file at line one.
ID,Region,Salary


Final should look like this.

Add headers to csv
ID,Region,Salary
1,EAST,100
2,WEST,200
3,SOUTH,300
4,NORTH,400

with open("data1.csv","w") as f:
f.write()
Reply


Messages In This Thread
Insert header at first row, for existing csv - by mg24 - Oct-04-2022, 11:36 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Add\insert header row existing csv files mg24 0 743 Oct-05-2022, 06:11 AM
Last Post: mg24
  Insert a multiple constant value after header in csv file using python shantanu97 1 1,174 Apr-24-2022, 10:04 AM
Last Post: Pedroski55
  Insert using psycopg giving syntax error near "INSERT INTO" olgethorpe 4 15,714 Jul-21-2017, 07:39 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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