Dec-30-2018, 05:21 PM
Thanks for input stullis.
Have read the post 10 times or so, and still dont understand whats happening. And pasting it in, just gives me an error.
So not sure what to get out of this at this moment. :(
/ Carsten
Have read the post 10 times or so, and still dont understand whats happening. And pasting it in, just gives me an error.
So not sure what to get out of this at this moment. :(
/ Carsten
(Dec-30-2018, 12:36 AM)stullis Wrote: You can process this data more efficiently:
def pivot_table(data): output = [] length = len(data[0]) for i in range(length): output.append([datapoint[i] for datapoint in data]) return output pivoted_data = pivot_table(data["groups"][0]["columns"]) for row in pivoted_data: t.add_row(row)The output of the function is:
To retrieve only the first ten rows, you can modify the function above to only iterate over ten items. Although, it sounds like you may be more interested in doing aggregate calculations on the data set. Have you looked at namedtuple() in the collections module? That creates a data structure that's optimized for aggregate functions like sum, average, etc.
Output:[[20110911, 'Sunday', 1, 2011, 'Bears', 'Falcons', 'home', 30, 12, 2.0, 40.5], [20110918, 'Sunday', 2, 2011, 'Bears', 'Saints', 'away', 13, 30, 6.0, 47.0]]