I have a CSV file which contains multiple Row and columns. Based on the if condition I need to filter the date and I want to write that filtered data to new CSV file.
So I have written this below code for the same however I'm getting only one row but we have many rows in the filtered data.
Could you please help me to fix the issue.
Code:
import CSV
with open('testfilename.csv','r') ad file
csv_reader = csv.reader (csv_file)
rows = [ row for row in csv_reader]
filtered_rows1 = []
filtered_rows2 = []
for row in rows:
if(row[3] == "CRITICAL"):
filtered_rows1.append(row)
with open('Critical.csv','w', newline='') as csv_file
csv_writer = CSV.writer(csv_file)
for row in filtered_rows1:
csv_writerow(row)
elif(row[3] == "URGENT"):
filtered_rows2.append(row)
with open('Urgent.csv','w', newline='') as csv_file
csv_writer = CSV.writer(csv_file)
for row in filtered_rows2:
csv_writerow(row)