I have a Python code which filters the data according to specific column and creates multiple CSV files.
Here is my main csv file:
Name, City, Email
john cty_1 [email protected]
jack cty_1 [email protected]
...
Ross cty_2 [email protected]
Rachel cty_2 [email protected]
...
My python logic currently creates separate csv for separate city. Existing python logic is:
from itertools import groupby
import csv
with open('filtered_final.csv') as csv_file:
reader = csv.reader(csv_file)
next(reader) #skip header
#Group by column (city)
lst = sorted(reader, key=lambda x : x[1])
groups = groupby(lst, key=lambda x : x[1])
#Write file for each city
for k,g in groups:
filename = k[21:] + '.csv'
with open(filename, 'w', newline='') as fout:
csv_output = csv.writer(fout)
csv_output.writerow(["Name","City","Email"]) #header
for line in g:
csv_output.writerow(line)
Now, I want to remove the "City" Column on each new CSV files.