Pivot Table/Groupby/Sum question
petr.jakes.tpc at gmail.com
petr.jakes.tpc at gmail.com
Wed Jan 2 20:16:18 EST 2008
> So the data comes in as a long list. I'm dealing with some
> information on various countries with 6 pieces of information to
> pivot. Just to make it simple it's like a video store database. The
> data is like [Country, Category, Sub Category, Film Title, Director,
> Number of Copies]. data = [['Italy', 'Horror', '70s', 'Suspiria',
> 'Dario Argento', 4],['Italy', 'Classics', 'Neo-Realist', 'Otto e
> Mezzo', 'Fellini', 3],['Italy', 'Horror', '70s', 'Profondo Rosso',
> 'Dario Argento', 4],...]. So there are 4 copies of Suspiria and 3 of
> 8 1/2. What I want is the total number of films for each country,
> category and subcategory, ie there are 11 Italian films and 8 Italian
> horror films from the 70s, etc...I will then output the data like this
> | Horror | Classics ...
> Total | 70s Slasher | Neo-Realist Western ...
> Total
> America 200 20 30 0 10 ...
> Argentina 304 1 0 0 0 ...
> ....
> Italy 11 7 0 3 0 ...
Did you mean your table has to look like the following?
| Horror | Horror | Classics | Classics
Total | 70s | Slasher | Neo-Realist | Western ...
Total
America 200 20 30 0 10 ...
Argentina 304 1 0 0 0 ...
....
More information about the Python-list
mailing list