out[ ]key key one two one - two - in this casewe grouped the data using two keysand the resulting series now has hierarchical index consisting of the unique pairs of keys observedin [ ]means unstack(out[ ]key one two key - - in these examplesthe group keys are all seriesthough they could be any arrays of the right lengthin [ ]states np array(['ohio''california''california''ohio''ohio']in [ ]years np array([ ]in [ ]df['data 'groupby([statesyears]mean(out[ ]california - ohio - frequently the grouping information to be found in the same dataframe as the data you want to work on in that caseyou can pass column names (whether those are stringsnumbersor other python objectsas the group keysin [ ]df groupby('key 'mean(out[ ]data data key - in [ ]df groupby(['key ''key ']mean(out[ ]data data key key one two one - two - you may have noticed in the first case df groupby('key 'mean(that there is no key column in the result because df['key 'is not numeric datait is said to be nuisance columnwhich is therefore excluded from the result by defaultall of the data aggregation and group operations www it-ebooks info