csv 文件具有以下内容:
Cautus Drogisterijen B.V.
Cautus Drogisterijen B.V.
Clever Franke
De Inrichting
Teva Pharmaceuticals Europe B.V.
名称从 csv 导入,然后转换等。
我有以下脚本:
#Gegevens
l = (gegevens)
#script
#Welke sleutels moet hij pakken
sortkey = operator.itemgetter(1,5)
#De identieke sleutel selecteren
l_clean = sorted(l,key=sortkey)
#delijst maken
l_final = [(k, list(v)) for k,v in groupby(l_clean, key = operator.itemgetter(1))]
#importeer csv optie
import csv
#bestand kiezen
with open('export.csv', 'wb') as f:
#Write
writer = csv.writer(f)
#loop over de lijst
for k,v in l_final:
#welke gegevens hij moet tonen
info_rest = v[0][:5]+v[0][5:]
#combineerd de verzekeringen
info_combine = map(operator.itemgetter(5),v)
uniekid = k
verzl = info_combine
name = info_rest[0]
risicoadr = info_rest[2]
polisnummer = info_rest[3]
relatienummer = info_rest[4]
aanhef = info_rest[6]
contactpersoon = info_rest[7]
emailadr = info_rest[8]
klantgegevens = []
#lijst met alle gegevens
klantgegevens1 = [uniekid,naam,verz,risicoadr,polisnummer,relatienummer,aanhef,contactpersoon,emailadr]
klantgegevens.append (klantgegevens1)
for i, w in enumerate(name):
print (i,w)
#welke gegevens hij erin moet schrijven
writer.writerow(klantgegevens)
这产生了这个输出:
(0, 'C')
(1, 'a')
(2, 'u')
(3, 't')
(4, 'u')
(5, 's')
(6, ' ')
(7, 'D')
(8, 'r')
(9, 'o')
(10, 'g')
(11, 'i')
(12, 's')
(13, 't')
(14, 'e')
(15, 'r')
(16, 'i')
(17, 'j')
(18, 'e')
(19, 'n')
(20, ' ')
(21, 'B')
(22, '.')
(23, 'V')
(24, '.')
(0, 'C')
(1, 'a')
(2, 'u')
(3, 't')
(4, 'u')
(5, 's')
(6, ' ')
(7, 'D')
(8, 'r')
(9, 'o')
(10, 'g')
...
如您所见,他在名称中的每个字母上循环并给该字母一个数字,但我想要的是我的输出如下所示:
(0, 'cautus drogisterij B.V.')
(1, 'cautus drogisterij B.V.')
每个名字都有一个数字。