I am generating a dictionary out of multiple .csv files and it looks like this (example):
dtDict = {'AV-IM-1-13991730': {'6/1/2014 0:10': '0.96','6/1/2014 0:15': '0.92','6/1/2014 0:20': '0.97'},'AV-IM-1-13991731': {'6/1/2014 0:10': '1.96','6/1/2014 0:15': '1.92','6/1/2014 0:20': '1.97'},'AV-IM-1-13991732': {'6/1/2014 0:10': '2.96','6/1/2014 0:15': '2.92','6/1/2014 0:20': '2.97'},'AV-IM-1-13991733': {'6/1/2014 0:10': '3.96','6/1/2014 0:15': '3.96','6/1/2014 0:20': '3.97'}}
I want to save it to a .csv file in the following format:
timestamp,AV-IM-1-13991730,AV-IM-1-13991731,AV-IM-1-13991732,AV-IM-1-13991733
6/1/2014 0:10,0.96,1.96,2.96,3.96
6/1/2014 0:15,0.92,1.92,2.92,3.96
6/1/2014 0:20,0.97,1.97,2.97,3.97
The piece of code I have as of now (related to this objective):
header = '''# file...... Recorder file
# date...... Thu Mar 12 14:35:32 2015
# user...... Sri
# host...... (null)
# group..... None
# property.. AVA Measurements
# limit.....
# interval..''' testpower = open("custpower.csv",'w')
testpower.writelines([header,'\n','# timestamp\n'])
...
for key, value in dtDict.iteritems():#Still trying to figure out how to write to custpower.csv
I tried doing something similar to this:
for key, value in dtDict.iteritems():testpower.writelines([key,',',','.join(value),'\n'])
but it didnot quite do what I was trying to do.