Dec-30-2018, 12:36 AM
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:
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]]
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.