需要将ID.csv的蛋白质从name_or.csv中找到,并补充name和organism信息,最后写入了seq_sim_all.csv中
ID.csv
name_or.csv
seq_sim.all.csv
代码如下:
import csv
f = open('seq_sim_all.csv', 'w', encoding = 'utf-8', newline='')
csv_writer = csv.writer(f)
csv_writer.writerow(['Database ID', 'Name', 'Organism'])
with open('ID.csv','r',encoding='utf8') as fp1:
list1 = [i for i in csv.reader(fp1)]
print(list1)
with open('name_or.csv','r',encoding='utf8') as fp2:
list2 = [i for i in csv.reader(fp2)]
print(list2)
for i in list1:
for j in list2:
if i[0] == j[0]:
csv_writer.writerow([i[0], j[1], j[2]])
print(i[0], j[0], j[1], j[2])