I have d1, d2, ..., dn
dictionaries of the same len
and need to dump them into the columns of a new csv
file.
I would like the file to have its headers and to look pretty much like this:
|STAGE 1 | |STAGE 2 | |TOTAL |
SIM d1 d2 d3 d4 d5 d6 d7 d8 d9 d10 d11 d12 d13 d14 d15
event 1
event 2
event 3
event 4
event n
Each d
column should have the values of the corresponding dictionary
aligned below, and a tab
should work well in order to separate each column.
I know I could create a csv
file like this:
import csv
my_d = {"STAGE 1": 1, "STAGE 2": 2, "TOTAL": 3}
with open('mycsvfile.csv', 'wb') as csvfile:
w = csv.DictWriter(csvfile, my_d.keys())
w.writeheader()
w.writerow(my_d)
but I can't seem to find my way out and also I failed to figure out how to make headers like d1
appear as sub-headers. How could this be done in Python?