Novice Python just on the road, in the actual work encountered title The problem, try to use python3 simple implementation, welcome Master to come to optimize
ImportCSV#Open the file, with open can not be deliberately closed file, Python3 does not support files () Open, only with open ()With open ("Dk0519_1.csv","R", encoding="Utf-8") as Csv_file:#read the CSV file and return the iteration typeRead =Csv.reader (csv_file) alist=[] bdict=[] cdict=[] tmp= [] forIinchread:alist.append (I[0].split ("\ t")) forAinchAlist[1:]: Print(a) bdict.append ((A[0].split ("?") [0],a[1])) forBinchBdict:num= Int (b[1]) J= Bdict.index (b) + 1 whileJ <= (Len (bdict)-1) : ifB[0] not inchtmp:ifB[0] = =bdict[j][0]: num+ = Int (bdict[j][1]) J+ = 1Else: J+=1Else: J+=1ifB[0] not inchTmp:cdict.append ((b[0],num))Else: Passtmp.append (b[0]) with open ('Re_dk0519_1.csv','W', encoding="Utf-8") as Write_csvfile:writer=Csv.writer (write_csvfile) writer.writerows (cdict)
Python3 simple implementation reads content from a CSV file and classifies content into statistics