我正在尝试将数据从 CSV 逐行加载到字典中。我正在尝试添加没有重复的数据:," imsi = line[1] & site= line[3]"
. 如果 imsi 和 site 已经存在于字典中,我只想用新行聚合值而不重复。
imsi = line[1] & site= line[3]
20190102,100000000204197,google.com,4799,1394,1,1
20190102,100000000204197,yahoo.com,11626,5635,5,4
20190102,100000000204197,yahoo.com,11625666,563345,5,12
20190102,41602323232,youtube.com,7875,5710,4,4
20190102,41602323232,,youtube.com,11,3
from datetime import datetime
from dateutil.parser import parse
from collections import Counter
import csv
with open('/home/mahmoudod/Desktop/Tareq-Qassrawi/report.txt','r') as rf:
reader = csv.reader(rf)
with open ('/home/mahmoudod/Desktop/Tareq-Qassrawi/writer.txt','w') as wf:
hashing_table = {}
connection_val= 0
connection_val_2=0
for line in reader:
key = int(line[1])
if key != hashing_table.items():
hashing_table =({'IMSI':key
,'SITE':str(line[2])
,'DATE':str(line[0])
,'linkup' :int(line[3])
,'linkdown':int(line[4])
,'count':int(line[5])
,'connection':int(line[6])
})
connection_val = connection_val + int(hashing_table.get('connection'))
print (connection_val)
else:
connection_val_2 = connection_val_2 + int(hashing_table.get('connection'))
print (connection_val_2)