IIUC,
df.groupby(['category','sex']).B.count().unstack().reset_index()\.plot.bar(x = 'category', y = ['f', 'm'])
Edit: If you have multiple columns, you can use groupby, count and droplevel.
new_df = df.groupby(['category','sex']).count().unstack()new_df.columns = new_df.columns.droplevel()new_df.reset_index().plot.bar()