I currently have a dictionary who values are lists.
Example: {1: [12, 13, 14, 15], 2: [12, 13, 14, 15], 3: [12, 13, 14, 15]} and so on.
I have 20000 keys, and each list contains 80 values.
I am trying to output this into a CSV file, but have had no luck using Dictwriter. Here is part of my code:
for i in range(0, 3):
filetxt = "\\Level_3\\" + nonsbar[i]
filedata = list(csv.reader(open(filetxt,'rb'), delimiter='\t'));
for j in range (1, len(filedata)):
tempid = filedata[j][0]
idind = tempid.index('|')
geneid = tempid[idind+1:len(tempid)]
genecount = filedata[j][1]
nconn[geneid].append(genecount)
for keys in nconn.keys():
nconn[keys] = zip(nconn[keys])
print "convert to table"
nkeys = nconn.keys()
filetxt = open('nonsmoke.csv', 'wb')
nonsmoketab = csv.DictWriter(filetxt, nkeys,delimiter=',')
nonsmoketab.writeheader()
nonsmoketab.writerow(nconn)
I get an ouput like this:
114787 114786
[('161.00',), ('985.00',), ('68.00',)] [('9.00',), ('19.00',), ('2.00',)]
I instead want this:
114787 114786
161 9
985 19
68 2