$ 0 0 You can also use thispd.pivot_table(df, values = 'B', index = 'category', columns = 'sex', aggfunc = lambda x: len(x)).plot.bar()which results in exactly the same plot.