gpt4 book ai didi

python - 数据集的每个变量的 seaborn.boxplot

转载 作者:行者123 更新时间:2023-12-02 00:33:58 60 4
gpt4 key购买 nike

我正在使用 Wisconsin dataset 。要显示 Y 轴是数据帧变量(例如:radius_mean)且 X 轴是诊断的箱线图,我执行以下操作:

sns.boxplot(x='label', y='radius', data=dsWisconsin)

(dsWisconsin 是从 .csv 加载 pandas 的数据框)

我的问题是,我怎样才能显示每个变量的所有箱线图(在网格中),而不是为每个变量执行前面的代码?

例如,类似这样的东西,但每个变量的箱线图来自威斯康星州:

Multiple histogram

         id diagnosis  radius_mean  texture_mean  perimeter_mean  area_mean  smoothness_mean  compactness_mean  concavity_mean  concave points_mean  symmetry_mean  fractal_dimension_mean  radius_se  texture_se  perimeter_se  area_se  smoothness_se  compactness_se  concavity_se  concave points_se  symmetry_se  fractal_dimension_se  radius_worst  texture_worst  perimeter_worst  area_worst  smoothness_worst  compactness_worst  concavity_worst  concave points_worst  symmetry_worst  fractal_dimension_worst
0 842302 M 17.99 10.38 122.80 1001.0 0.11840 0.27760 0.3001 0.14710 0.2419 0.07871 1.0950 0.9053 8.589 153.40 0.006399 0.04904 0.05373 0.01587 0.03003 0.006193 25.38 17.33 184.60 2019.0 0.1622 0.6656 0.7119 0.2654 0.4601 0.11890
1 842517 M 20.57 17.77 132.90 1326.0 0.08474 0.07864 0.0869 0.07017 0.1812 0.05667 0.5435 0.7339 3.398 74.08 0.005225 0.01308 0.01860 0.01340 0.01389 0.003532 24.99 23.41 158.80 1956.0 0.1238 0.1866 0.2416 0.1860 0.2750 0.08902
2 84300903 M 19.69 21.25 130.00 1203.0 0.10960 0.15990 0.1974 0.12790 0.2069 0.05999 0.7456 0.7869 4.585 94.03 0.006150 0.04006 0.03832 0.02058 0.02250 0.004571 23.57 25.53 152.50 1709.0 0.1444 0.4245 0.4504 0.2430 0.3613 0.08758
3 84348301 M 11.42 20.38 77.58 386.1 0.14250 0.28390 0.2414 0.10520 0.2597 0.09744 0.4956 1.1560 3.445 27.23 0.009110 0.07458 0.05661 0.01867 0.05963 0.009208 14.91 26.50 98.87 567.7 0.2098 0.8663 0.6869 0.2575 0.6638 0.17300
4 84358402 M 20.29 14.34 135.10 1297.0 0.10030 0.13280 0.1980 0.10430 0.1809 0.05883 0.7572 0.7813 5.438 94.44 0.011490 0.02461 0.05688 0.01885 0.01756 0.005115 22.54 16.67 152.20 1575.0 0.1374 0.2050 0.4000 0.1625 0.2364 0.07678

最佳答案

您可以将数据转换为整齐的格式并使用 FacetGrid

df = df.melt(id_vars=['id', 'diagnosis'])
df[:3]
# id diagnosis variable value
# 0 842302 M radius_mean 17.99
# 1 842517 M radius_mean 20.57
# 2 84300903 M radius_mean 19.69

cols = ['radius_mean', 'texture_mean', 'perimeter_mean', 'area_mean']
grid = sns.axisgrid.FacetGrid(df[df.variable.isin(cols)], col='variable', sharey=False)
grid.map(sns.boxplot, 'diagnosis','value')

enter image description here

关于python - 数据集的每个变量的 seaborn.boxplot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50552853/

60 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com