bucket categorization using cutin [ ]frame dataframe({'data 'np random randn( )'data 'np random randn( )}in [ ]factor pd cut(frame data in [ ]factor[: out[ ]categoricalarray([(- ](- - ](- ]( ](- ]( ](- ](- ]( ]( ]]dtype=objectlevels ( )index([(- - ](- ]( ]( ]]dtype=objectthe factor object returned by cut can be passed directly to groupby so we could compute set of statistics for the data column like soin [ ]def get_stats(group)return {'min'group min()'max'group max()'count'group count()'mean'group mean()in [ ]grouped frame data groupby(factorin [ ]grouped apply(get_statsunstack(out[ ]count max mean min data (- - - (- - - - ( - ( - these were equal-length bucketsto compute equal-size buckets based on sample quantilesuse qcut 'll pass labels=false to just get quantile numbers return quantile numbers in [ ]grouping pd qcut(frame data labels=falsein [ ]grouped frame data groupby(groupingin [ ]grouped apply(get_statsunstack(out[ ]count max mean min - - - - - - - - - - - - - - - group-wise operations and transformations www it-ebooks info