![](/img/trans.png)
[英]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.