Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
482 views
in Technique[技术] by (71.8m points)

Python Pandas statsmodels.graphics mosaic plot except for contingency table data?

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...