I have a three layed dictionary that I need to save it in csv format. I followed the code in this post. but i get only two rows with all the data dumped in one row.
How can I separate data and write them into separate cells.
{'Alpha': {'2010': {'216': 0.0, '217': 0.0, '218': 195.37308756510416}}}
There are other keys (Beta
and Omega
) at the same level as Alpha
.
I'd like the final product to look like:
Alpha,2010,216,0.0
Alpha,2010,217,0.0
Alpha,2010,218,195.37308756510416
.....
Beta, .....
and preferably save it in a .csv
file, but text file will do too.
This code is what I have tried.
with open('mycsvfile.csv', 'wb') as f:
w = csv.DictWriter(f, datadictionary.keys())
w.writeheader()
w.writerow(datadictionary)
Thanks