Cloud Stack Ninja

I have a dictionary (cell_summary) with 46 items(b1c0,b1c1,b1c2..) in it. Each item in "cell_summary" is a dictionary with 8 items in it. Each of the 8 items is an array of numbers. I would like to convert the 46 items as 46 sheets in a single CSV or excel workbook. 8 key names must be the column names in each sheet and the corresponding data should come in the same column. See the images attached to get a clear Idea of the data. Each sheet in the CSV file should have all the 8 field names and the values in the array must appear in the column of the corresponding field.

I tried the below code. But, all the values in the array are being stored in only one cell of the CSV file. Please see the attached image for reference.

Please help me with this.

import csv
import itertools

with open("Cell Summary.csv", 'w', newline='' )as f:

    fields = ['IR', 'QC', 'QD', 'Tavg', 'Tmin', 'Tmax', 'chargetime', 'cycle']
    w = csv.DictWriter( f, fields )
    for key,val in sorted(cell_summary.items()):
        row = {'IR': key}

Structure of data in Cell_summary Required Data Arrangement in CSV file Data saved in CSV file with the above code

Read more here:

Content Attribution

This content was originally published by Pradyumna TK at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: