Skufnoo,222228888444,-6026769894509215039,ВупÑень пупÑень â¤ï¸â€ðŸ©¹ðŸ’—,AA2888 ចាក់បាល់និងកាសុីណូអនឡាញ (070645555),1746008070,False,False,4,True,False,0
mAtkmb,5213786988,4161254730445748607,ДаниÑль Блинов,AA2888 ចាក់បាល់និងកាសុីណូអនឡាញ (070645555),1746008070,False,False,False,False,False,0
Ethan58,222228888444,7737583697013043644,Ethan,AA2888 ចាក់បាល់និងកាសុីណូអនឡាញ (070645555),1746008070,False,False,4,True,False,0
sheluvjoseph,1421438213,8544915453690665435,អន សំអុល,AA2888 ចាក់បាល់និងកាសុីណូអនឡាញ (070645555),1746008070,False,False,5,True,False,0
并将它们写入新的 CSV 文件,如下所示:
Skufnoo,222228888444,-6026769894509215039,ВупÑень пупÑень â¤ï¸â€ðŸ©¹ðŸ’—,AA2888 ចាក់បាល់និងកាសុីណូអនឡាញ (070645555),1746008070,False,False,4,True,False,0
mAtkmb,5213786988,4161254730445748607,ДаниÑль Блинов,AA2888 ចាក់បាល់និងកាសុីណូអនឡាញ (070645555),1746008070,False,False,False,False,False,0
sheluvjoseph,1421438213,8544915453690665435,អន សំអុល,AA2888 ចាក់បាល់និងកាសុីណូអនឡាញ (070645555),1746008070,False,False,5,True,False,0
我尝试了以下代码,但它不起作用:
import csv
with open('members.csv', 'r', encoding="utf8") as in_file, open('members2.csv', 'w', encoding="utf8") as out_file:
writer=csv.writer(out_file)
tracks = set()
for row in in_file:
key = row[1]
if key not in tracks:
writer.writerow(row)
tracks.add(key)
非常感谢任何帮助。
in_data = csv.reader(in_file, delimiter=',')
代码中的所有其他行似乎都没问题。完整代码:
import csv
with open('members.csv', 'r', encoding="utf8") as in_file, open('members2.csv', 'w', encoding="utf8") as out_file:
in_data = csv.reader(in_file, delimiter=',')
writer=csv.writer(out_file)
tracks = set()
for row in in_data:
key = row[1]
if key not in tracks:
writer.writerow(row)
tracks.add(key)