I have a piece of code that generates a flawed CSV file that I cannot fix. I can however fix this after the fact. Here is the CSV file:
column_a, column_b, column_c, column_d
1, 2_a, 3_b, 4_c, 5_d
1, 2_a, 3_b, 4_c, 5_d
1, 2_a, 3_b, 4_c, 5_d
1, 2_a, 3_b, 4_c, 5_d
I would like to skip the first row and delete all the '1's in the csv file. I have the following code to try and remedy this but I cannot save this file for some reason. I want to edit the file, not create a new one and output results. Here is the code I am toying with:
import csv
file = 'file.csv'
csv_file = open(file)
csv_reader = csv.reader(csv_file)
next(csv_reader) # Skip first row
for row in csv_reader:
del row[0]
csv_reader.close()
It seems so simple yet I cannot manage to save these changes without maybe outputting to a separate file.