我创建了一个包含7个字段的csv文件,但我意识到只有一列(我想要7列,每列对应一个字段)
import csv
import random
with open('mydata2.csv','w',newline='') as f:
file=csv.writer(f)
file.writerow(['Prenom','Nom','Age','Lieux frequentés','Habitudes d achat','Horaire des activités','Centres d interet'])
for i in range (1,1000) :
Noms=['ahmed','slim','amal'] #many other first names
Prenoms=['Ben nasr','atay','abed'] #many other last names
....
file.writerow([random.choice(Prenoms),random.choice(Noms),random.randint(17,65),random.sample(Lfreq,4),random.sample(habitudes,3),random.sample(Hor,2), random.sample(Interest,3)])