I have a csv file with duplicate values in its first column, example:
mg,known,127
mg,unknown,142
pnt,known,37
pnt,unknown,0
lmo,known,75
lmo,unknown,3
sl,known,197
sl,unknown,21
oc,unknown,32
oc,known,163
sv,known,368
sv,unknown,308
az,unknown,6
az,known,241
bug,unknown,1
bug,known,167
li,unknown,15
li,known,174
lg,known,3
What I want to do is construct a new csv file such that example:
header1, known, unknown
mg, 127, 142
pnt, 37, 0
I am trying to figure out how I can really construct the row:
def read_stats(path):
has_seen = set()
with open(writepath, 'wb') as write_csv:
with open(path, 'r') as csv_file:
data_reader = csv.reader(csv_file, delimiter=',')
for line in data_reader:
if line[0] in has_seen:
This is where I am currently struck, do I have to keep a pointer to the next row?