经过审查,很少有人推荐类似的关于比较价值的话题,对我帮助不大
car.csv
tittle1,tittle2
bmw,2000
mercedes,2000
toyota,1000
honda,1500
geely,500
price.csv
ori_price1,new_price2
2000,5000
1000,2500
结果应该是 标题1,标题2
bmw,5000
mercedes,5000
toyota,2500
honda,1500
geely,500
我发现下面的代码与结果非常接近
import csv
with open('car.csv', 'r') as csv_file, open('price.csv', 'r', newline='') as csv_file2 \
,open('result.csv', 'w', newline='') as new_file:
csv_reader = csv.DictReader(csv_file)
csv_reader2 = csv.DictReader(csv_file2)
csv_writer = csv.writer(new_file)
csv_writer.writerow([ 'tittle1', 'title2'])
for row1,row2 in zip(csv_reader,csv_reader2):
csv_writer.writerow([row1['tittle1'],row1['tittle2'],row2['new_price2']])
使用
pandas
,它可以非常简单:相关问题 更多 >
编程相关推荐