How to replace entire column with python.
example i have a csv file like below
ID,Name,Age,Group
001,Member1,25,a
002,Member2,30,c
003,Member3,29,b
now i need to replace all values for group column to d
How to replace entire column with python.
example i have a csv file like below
ID,Name,Age,Group
001,Member1,25,a
002,Member2,30,c
003,Member3,29,b
now i need to replace all values for group column to d
Here an answer with the python csv module. It just reads out a csv file, changes the "Group" column and writes the row to a new csv file.
import csv
with open("foo.csv") as csv_read_file:
reader = csv.DictReader(csv_read_file)
with open("foo_new.csv", "w") as csv_write_file:
writer = csv.DictWriter(csv_write_file, fieldnames=["ID", "Name", "Age", "Group"])
writer.writeheader()
for row in reader:
row["Group"] = "d"
writer.writerow(row)