[英]how do i search for a row in a csv in python and putting it in a different file using this code:
import re
import csv
with open('a.csv','r') as f:
r = csv.reader(f)
dict2 = {row[0]: row[1:] for row in r}
with open('b.csv', 'r') as f:
r = csv.reader(f)
dict1 = {row[0]: row[1:] for row in r}
fine = {k: (dict1[k], dict2[k]) for k in set(dict1).intersection(dict2)}
with open('c.csv', 'w') as f:
w = csv.writer(f)
for value in fine.items():
w.writerow(value)
please help, I cant find how to input it into another csv, I am doing this for school so please can you help me solve the way to actually change it so that is searches for a row that includes certain words in the first two csv s 请帮忙,我找不到如何将其输入到另一个csv中,我正在学校上学,所以请您能帮我解决实际更改它的方法,以便在前两个csv中搜索包含某些单词的行
One of those? 其中之一?
for value in fine.items()::
unpacked_value = [elem for lst in value for elem in lst]
w.writerow(unpacked_value)
for value in fine:
for row in fine[value]:
w.writerow((value, row))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.