Hi!
I have two tsv files that I want to merge together. They have one column, the key, which is the same and I want to get the values of both files in one.
How do I do this? my code gives me this Type error: unsupported operand type(s) for +: 'collections.defaultdict' and 'collections.defaultdict'
This is the code that I have now.
Thanks in advance!
import csv
from collections import defaultdict
contig_map = defaultdict(list)
scaffold_map = defaultdict(list)
with open('file_one.txt', 'r') as file_one:
csv_reader = csv.reader(file_one, delimiter = "\t")
for row in csv_reader:
contig_map[row[0]].append(row[-1])
with open('file_two.txt', 'r') as file_two:
csv_reader = csv.reader(file_two, delimiter = "\t")
for row in csv_reader:
scaffold_map[row[0]].append(row[1:])
with open('merged_file', 'w') as out_file:
merged = [contig_map + scaffold_map]
d = {}
for k in contig_map.iterkeys():
d[k] = tuple(d[k] for d in merged)
print d