How do I produce a mosaic plot in Python with contingency table data? I have a Pandas DataFrame like so:
import from statsmodels.graphics.mosaicplot import mosaic
pd.DataFrame(df.groupby(['device_type', 'failure'])['device'].nunique() / df['device'].nunique())
device
device_type failure
S 0 0.453379
1 0.035928
W 0 0.359281
1 0.035928
Z 0 0.187340
1 0.018820
I have seen simple toy examples that produce mosaics using mosaic
from statsmodels.graphics
when fed a Pandas DataFrame with two columns specified. However, in this case, I do not have just 2 columns of data but rather a contingency table.
Additionally, is there a prettier mosaic()
elsewhere for Python? I tried looking for one without luck.
question from:
https://stackoverflow.com/questions/65949461/python-pandas-statsmodels-graphics-mosaic-plot-except-for-contingency-table-data 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…