I have a 14000 lines with two fields each csv file and am trying to remove some rows that occur randomly. I intend to keep everything besides the rows containing any of the following: "Station Name", "Location Code", "Parameter".
I am trying to open the file containing the data together with a new empty csv file that will be used to write the new data into. I am trying to loop through each line of the csv file and write into the new file only the lines which do not have the first field equal to any of the mentioned values.
I am trying the following but I end up with an exact copy of the initial data.
import csv
with open('combined_csv.csv', newline='') as inp, open('edited.csv', 'w', newline='') as out:
writer = csv.writer(out)
for row in csv.reader(inp):
if row[0] != "Station Name" and "Location Code" and "Parameter":
writer.writerow(row)
Any help is appreciated