sex day female fri sat sun thur male fri sat sun thur tip_pct no yes size no yes this table could be augmented to include partial totals by passing margins=true this has the effect of adding all row and column labelswith corresponding values being the group statistics for all the data within single tier in this below examplethe all values are means without taking into account smoker vs non-smoker (the all columnsor any of the two levels of grouping on the rows (the all row)in [ ]tips pivot_table(['tip_pct''size']rows=['sex''day']cols='smoker'margins=trueout[ ]size tip_pct smoker no yes all no yes all sex day female fri sat sun thur male fri sat sun thur all to use different aggregation functionpass it to aggfunc for example'countor len will give you cross-tabulation (count or frequencyof group sizesin [ ]tips pivot_table('tip_pct'rows=['sex''smoker']cols='day'aggfunc=lenmargins=trueout[ ]day fri sat sun thur all sex smoker female no yes male no yes all if some combinations are empty (or otherwise na)you may wish to pass fill_valuein [ ]tips pivot_table('size'rows=['time''sex''smoker']cols='day'aggfunc='sum'fill_value= out[ ]day fri sat sun thur time sex smoker dinner female no data aggregation and group operations www it-ebooks info