我有一个 csv 文件,其第一列中有重复值,例如:
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
我想要做的是构建一个新的 csv 文件,例如:
header1, known, unknown
mg, 127, 142
pnt, 37, 0
我试图弄清楚我如何才能真正构建行:
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:
这是我目前感到震惊的地方,我是否必须保留指向下一行的指针?