一个csv包含不同的类别名称,另一个包含不同的地方。我想将一个类别放到所有地方并将它们连接起来。我怎么能在python中做到这一点? csv 1栏:类别(近400个) csv 2栏:面积(差不多3000)
答案 0 :(得分:0)
import csv
import itertools
with open('categories.csv') as cats, open('places.csv') as places, open('output.csv', 'w') as fout:
outfile = csv.writer(fout)
places = list(csv.reader(places))
outfile.writerow(["{}{}".format(cat, place) for cat, place in itertools.product(csv.reader(cats), places)])