python - FaceGrid of nested Pandas dataframe -
i need boxplot following dataframe, using facegrid, in such way each row of grid correspond particular week, given k_week
, , columns columns of dataframe (sensitivity
, specificity
, etc.). each boxplot should contain 6 models ('sig', 'mrm', 'mean', etc)
here example of single row (i succeeded it):
now need such 6 rows on single figure ,using facegrid.
dataframe:
df.groupby('k_week').head(6) sensitivity specificity accuracy ppv auc k_week model 0 0.609948 0.867516 0.717291 0.776004 0.813680 4 sig 1 0.586824 0.851647 0.685525 0.757557 0.784805 4 mrm 2 0.581152 0.842510 0.670357 0.749651 0.737269 4 mean 3 0.473386 0.601827 0.395841 0.556193 0.542679 4 rmssd 4 0.511344 0.717240 0.499148 0.644086 0.626719 4 missval 5 0.454625 0.523924 0.356061 0.508448 0.501661 4 rand 0 0.792619 0.764423 0.755839 0.777934 0.835871 6 sig 1 0.722077 0.758113 0.733090 0.740845 0.803949 6 mrm 2 0.633899 0.735877 0.688298 0.687011 0.736115 6 mean 3 0.437296 0.613582 0.510095 0.529108 0.544014 6 rmssd 4 0.517309 0.740986 0.647588 0.633803 0.653312 6 missval 5 0.439582 0.532452 0.477898 0.502504 0.499943 6 rand 0 0.716681 0.778103 0.762680 0.747469 0.826501 8 sig 1 0.675493 0.772834 0.747396 0.724285 0.796723 8 mrm 2 0.633127 0.743852 0.710935 0.688628 0.732537 8 mean 3 0.430421 0.685597 0.576665 0.558327 0.588858 8 rmssd 4 0.577817 0.671838 0.636629 0.624945 0.652066 8 missval 5 0.470138 0.520199 0.494885 0.497872 0.505699 8 rand 0 0.744211 0.823977 0.778372 0.787783 0.849315 12 sig 1 0.672321 0.826884 0.763375 0.756750 0.812551 12 mrm 2 0.623856 0.700291 0.633579 0.665608 0.719829 12 mean 3 0.405223 0.711921 0.538847 0.572755 0.581289 12 rmssd 4 0.592623 0.751062 0.664152 0.679169 0.709493 12 missval 5 0.543888 0.463655 0.450788 0.496762 0.490970 12 rand 0 0.775064 0.794737 0.821246 0.783939 0.855578 20 sig 1 0.734351 0.745820 0.778527 0.739525 0.809667 20 mrm 2 0.571756 0.759133 0.742810 0.656285 0.724444 20 mean 3 0.649109 0.433437 0.582287 0.551816 0.568039 20 rmssd 4 0.540712 0.820743 0.785873 0.667039 0.741546 20 missval 5 0.550127 0.448916 0.546867 0.506564 0.498109 20 rand 0 0.813607 0.824252 0.891650 0.817440 0.889695 50 sig 1 0.671687 0.789921 0.850381 0.714253 0.826069 50 mrm 2 0.677002 0.769764 0.839411 0.710398 0.772619 50 mean 3 0.410524 0.658583 0.681270 0.499830 0.563487 50 rmssd 4 0.630758 0.773543 0.831970 0.682164 0.778421 50 missval 5 0.609142 0.384882 0.638997 0.525116 0.496973 50 rand
you have first melt data column names become values in column.
print(df.head(10)) sensitivity specificity accuracy ppv auc k_week model 0 0.609948 0.867516 0.717291 0.776004 0.813680 4 sig 1 0.586824 0.851647 0.685525 0.757557 0.784805 4 mrm 2 0.581152 0.842510 0.670357 0.749651 0.737269 4 mean 3 0.473386 0.601827 0.395841 0.556193 0.542679 4 rmssd 4 0.511344 0.717240 0.499148 0.644086 0.626719 4 missval 5 0.454625 0.523924 0.356061 0.508448 0.501661 4 rand 0 0.792619 0.764423 0.755839 0.777934 0.835871 6 sig 1 0.722077 0.758113 0.733090 0.740845 0.803949 6 mrm 2 0.633899 0.735877 0.688298 0.687011 0.736115 6 mean 3 0.437296 0.613582 0.510095 0.529108 0.544014 6 rmssd df = df.melt(id_vars=['k_week', 'model']) print(df.head(10)) k_week model variable value 0 4 sig sensitivity 0.609948 1 4 mrm sensitivity 0.586824 2 4 mean sensitivity 0.581152 3 4 rmssd sensitivity 0.473386 4 4 missval sensitivity 0.511344 5 4 rand sensitivity 0.454625 6 6 sig sensitivity 0.792619 7 6 mrm sensitivity 0.722077 8 6 mean sensitivity 0.633899 9 6 rmssd sensitivity 0.437296 grid = sns.facetgrid(df, row='k_week', col='variable') grid.map_dataframe(sns.boxplot, x='model', y='value')
Comments
Post a Comment