[英]Joining all rows of a CSV file that have the same 1st column value in Python
[英]joining all rows of a csv file that have the same first column with python
import csv
filename = "Filename.csv"
csvList = list(csv.reader(open(filename)))
csvDict = {}
for i in csvList :
if i[0] in csvDict :
csvDict[i[0]].append(i[1])
else :
csvDict[i[0]] = [i[1]]
print(csvDict)
使用字典创建适当的输出格式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.