matplotlib - Boxplot with pandas and groupby -


i have following dataset sample:

     0         1 0    0  0.040158 1    2  0.500642 2    0  0.005694 3    1  0.065052 4    0  0.034789 5    2  0.128495 6    1  0.088816 7    1  0.056725 8    0 -0.000193 9    2 -0.070252 10   2  0.138282 11   2  0.054638 12   2  0.039994 13   2  0.060659 14   0  0.038562 

and need box , whisker plot, grouped column 0. have following:

plt.figure() grouped = df.groupby(0) grouped.boxplot(column=1) plt.savefig('plot.png') 

but end 3 subplots. how can place 3 on 1 plot? thanks. enter image description here

i don't believe need use groupby.

df2 = df.pivot(columns=df.columns[0], index=df.index) df2.columns = df2.columns.droplevel()  >>> df2 0          0         1         2 0   0.040158       nan       nan 1        nan       nan  0.500642 2   0.005694       nan       nan 3        nan  0.065052       nan 4   0.034789       nan       nan 5        nan       nan  0.128495 6        nan  0.088816       nan 7        nan  0.056725       nan 8  -0.000193       nan       nan 9        nan       nan -0.070252 10       nan       nan  0.138282 11       nan       nan  0.054638 12       nan       nan  0.039994 13       nan       nan  0.060659 14  0.038562       nan       nan  df2.boxplot() 

boxplot


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -