we can just pass the dictin [ ]by_column people groupby(mappingaxis= in [ ]by_column sum(out[ ]blue red joe steve - wes - - jim travis - - the same functionality holds for serieswhich can be viewed as fixed size mapping when used series as group keys in the above examplespandas doesin factinspect each series to ensure that its index is aligned with the axis it' groupingin [ ]map_series series(mappingin [ ]map_series out[ ] red red blue blue red orange in [ ]people groupby(map_seriesaxis= count(out[ ]blue red joe steve wes jim travis grouping with functions using python functions in what can be fairly creative ways is more abstract way of defining group mapping compared with dict or series any function passed as group key will be called once per index valuewith the return values being used as the group names more concretelyconsider the example dataframe from the previous sectionwhich has people' first names as index values suppose you wanted to group by the length of the namesyou could compute an array of string lengthsbut instead you can just pass the len functionin [ ]people groupby(lensum(out[ ] - - data aggregation and group operations www it-ebooks info