Python creating a dictionary and swapping these into another file
- by satsurae
Hi all,
I have two tab delimited .csv file. From one.csv I have created a dictionary which looks like:
'EB2430': ' "\t"idnD "\t"yjgV "\t"b4267 "\n',
'EB3128': ' "\t"yagE "\t\t"b0268 "\n',
'EB3945': ' "\t"maeB "\t"ypfF "\t"b2463 "\n',
'EB3944': ' "\t"eutS "\t"ypfE "\t"b2462 "\n',
I would like to insert the value of the dictionary into the second.csv file which looks like:
"EB2430" 36.81 364 222 4 72 430 101 461 1.00E-063 237
"EB3128" 26.04 169 108 6 42 206 17 172 6.00E-006 45.8
"EB3945" 20.6 233 162 6 106 333 33 247 6.00E-005 42.4
"EB3944" 19.07 367 284 6 1 355 1 366 2.00E-023 103
With a resultant output tab delimited:
'EB2430' idnD yjgV b4267 36.81 364 222 4 72 430 101 461 1.00E-063 237
'EB3128' yagE b0268 26.04 169 108 6 42 206 17 172 6.00E-006 45.8
'EB3945' maeB ypfF b2463 20.6 233 162 6 106 333 33 247 6.00E-005 42.4
'EB3944' eutS ypfE b2462 19.07 367 284 6 1 355 1 366 2.00E-023 103
Here is my code for creating the dictionary:
f = open ("one.csv", "r")
g = open ("second.csv", "r")
eb = []
desc = []
di = {}
for line in f:
for row in f:
eb.append(row[1:7])
desc.append(row[7:])
di = dict(zip(eb,desc))
Sorry for it being so long-winded!! I've not been programming for long.
Cheers!
Sat