yes male male female male male female male female female male no thur lunch no sun dinner no sun dinner no thur lunch no sat dinner yes sat dinner yes sun dinner yes sat dinner yes sun dinner yes sun dinner what has happened herethe top function is called on each piece of the dataframethen the results are glued together using pandas concatlabeling the pieces with the group names the result therefore has hierarchical index whose inner level contains index values from the original dataframe if you pass function to apply that takes other arguments or keywordsyou can pass these after the functionin [ ]tips groupby(['smoker''day']apply(topn= column='total_bill'out[ ]total_bill tip sex smoker day time size tip_pct smoker day no fri female no fri dinner sat male no sat dinner sun male no sun dinner thur male no thur lunch yes fri male yes fri dinner sat male yes sat dinner sun male yes sun dinner thur female yes thur lunch beyond these basic usage mechanicsgetting the most out of apply is largely matter of creativity what occurs inside the function passed is up to youit only needs to return pandas object or scalar value the rest of this will mainly consist of examples showing you how to solve various problems using groupby you may recall above called describe on groupby objectin [ ]result tips groupby('smoker')['tip_pct'describe(in [ ]result out[ ]smoker no count mean std min max group-wise operations and transformations www it-ebooks info