Pivot Table/Groupby/Sum question

patrick.waldo at gmail.com patrick.waldo at gmail.com
Fri Dec 28 19:51:11 EST 2007


Petr, thanks for the SQL suggestion, but I'm having enough trouble in
Python.

John would you mind walking me through your class in normal speak? I
only have a vague idea of why it works and this would help me a lot to
get a grip on classes and this sort of particular problem.  The next
step is to imagine if there was another variable, like departments and
add up the information by name, department, and time, and so on...that
will come another day.

Thanks.



On Dec 29, 1:00 am, John Machin <sjmac... at lexicon.net> wrote:
> On Dec 29, 9:58 am, petr.jakes.... at gmail.com wrote:
>
> > What about to let SQL to work for you.
>
> The OP is "trying to learn how to make pivot tables from some excel
> sheets". You had better give him a clue on how to use ODBC on an
> "excel sheet" :-)
>
> [snip]
>
> > SELECT
> > NAME,
> > sum (AMOUNT) as TOTAL,
> > sum (case when (TIME_OF_DAY) = 'Morn' then AMOUNT else 0 END) as
> > MORN,
> > sum (case when (TIME_OF_DAY) = 'Aft' then AMOUNT else 0 END) as AFT
>
> This technique requires advance knowledge of what the column key
> values are (the hard-coded 'Morn' and 'Aft').
>
> <rant>
> It is the sort of thing that one sees when %SQL% is the *only*
> language used to produce end-user reports. Innocuous when there are
> only 2 possible columns, but bletchworthy when there are more than 20
> and the conditions are complex and the whole thing is replicated
> several times in the %SQL% script because either %SQL% doesn't support
> temporary procedures/functions or the BOsFH won't permit their use...
> not in front of the newbies, please!
> </rant>




More information about the Python-list mailing list