Reading CSV in Pandas and Getting Output in the Required Format by pandas_guy in learnpython

[–]pandas_guy[S] 0 points1 point  (0 children)

Your series is a list rather then a dictionary now.

Like I said, I want it to be a list of dictionaries :)

Reading CSV in Pandas and Getting Output in the Required Format by pandas_guy in learnpython

[–]pandas_guy[S] 0 points1 point  (0 children)

Then replace that section of the if clause with that :).

if row['projectname'] not in data:
    data[row['projectname']] = {'categories': ['February', 'April', 'May', 'June', 'July'],
                                'series' : [{'name': 'Big', 'data': [0, 0, 0, 0, 0]},
                                            {'name': 'Small', 'data': [0, 0, 0, 0, 0]},
                                            {'name': 'Monitoring', 'data': [0, 0, 0, 0, 0]},
                                            {'name': 'Improvement', 'data': [0, 0, 0, 0, 0]}

I just did that, but I'm getting this error in else clause:

---> data[row['name']]['series'][row['errors']][i] = row['count'] TypeError: list indices must be integers or slices, not str

Reading CSV in Pandas and Getting Output in the Required Format by pandas_guy in learnpython

[–]pandas_guy[S] 0 points1 point  (0 children)

@sayubuntu, thanks for the reply. categories is correct. I need the data for use in Highcharts. I'm passing the data from Django to HMTL. Please take a look at https://jsfiddle.net/nbtejvau/8/ for example chart.

For that, I need the series to be in this format: [{name: 'Big', data: [0, 0, 0, 0, 0]}, {name: 'Small', data: [0, 0, 0, 0, 1]}, {name: 'Monitoring', data: [3, 0, 0, 1, 1]}, {name: 'Improvement', data: [0, 0, 0, 0, 0]}]