NOTE: I am using python 2.6, and dictWriter class writeheader method doesn't exist. Is there any way to do it apart from writeheader method. I have dictionary something like below, it contains key and values as list of values.
My dictionary will have this , here i would like the output into a csv file which will have the below format.(in the tabular format, where keys will be header and list of values will be rows under the header).
TNB MX RNB
119338 0 2246
249613 0 2460
192442 0 2572
Dictionary -
{' TNB': ['119338', '249613', '192442', '265359', '118181', '127593', '193793', '197851'], ' Mx': ['0', '0', '0', '0', '0', '0', '0', '0'], ' RNB': ['2246', '2460', '2572', '2577', '2425', '2611', '2475', '2223'], ' HJKI': ['116194', '246239', '188942', '261824', '114798', '123983', '190336', '194836'], ' RMX': ['0', '0', '0', '0', '0', '0', '0', '0'], ' MNI': ['28162', '83380', '52093', '77327', '27670', '27800', '47879', '53353'], ' RDI': ['0', '0', '0', '0', '0', '0', '0', '0'], ' RTR ': ['3684', '2836', '3977', '3682', '3034', '3690', '3717', '3851'], ' FGH': ['0', '0', '0', '0', '0', '0', '0', '0'], ' RBK': ['11', '7', '9', '11', '7', '9', '10', '9'], ' GMT': ['211', '213', '198', '203', '207', '242', '218', '194'], ' PQR': ['530', '550', '578', '594', '600', '607', '607', '447'], ' FRT': ['1', '0', '0', '0', '1', '1', '1', '0'], ' GR': ['84269', '159946', '132802', '180736', '84017', '92418', '138665', '137424'], ' YT': ['1', '2', '2', '1', '1', '2', '1', '1'], ' OIT': ['118805', '249060', '191861', '264761', '117577', '126982', '193182', '197401'], ' NIP': ['0', '0', '0', '0', '1', '0', '0', '0'] }
My program snippet is like below. metDic is dictionary in above format.
resultFile = open('outputMet.csv','wb')
wr = csv.writer(resultFile,dialect='excel')
for key,values in metDic.items() :
wr.writerow(key)
wr.writerows(zip(values))
However with above code , i am able to write the the values but row after row, not in tabular format.
My output is :
TNB
119338
249613
192442
MX
0
0
0
RIP
2456
2742
Any suggestion would be helpful, as well i am restricted to use python 2.6 version.