python - Plot average on subplots (pandas) -
i've managed plot subplots groupby. have 2 columns 'a', , 'b', want plot on subplot (1 per value in 'b') respective averages. prepare data counting, dropping duplicates, , summing (if there more elegant way it, please let me know!). df = pd.dataframe([[1, 'cat1'], [1, 'cat1'], [4, 'cat2'], [3, 'cat1'], [5, 'cat1'],[1, 'cat2']], columns=['a', 'b']) df = df[['a','b']] df['count'] = df.groupby(['a','b'])['a'].transform('count') df = df.drop_duplicates(['a','b']) df = df.groupby(['a','b']).sum() then unstack , plot subplots: plot = df.unstack().plot(kind='bar',subplots=true, sharex=true, sharey=true, layout = (3,3), legend=false) plt.show(block=true) i add mean each category, have don't know: 1. how calculate mean. if calculate on unstacked groupby, mean of count, rather value 'a'....