gpt4 book ai didi

python - Seaborn 和 Pandas,分组箱线图

转载 作者:行者123 更新时间:2023-12-04 10:11:12 24 4
gpt4 key购买 nike

总的来说,我对 Python/data 还是很陌生,我很难理解这个问题

我目前有 3 个数据框,看起来像这样

| A | B | C | Type  | 
| 1 | 2 | 6 | Worst |
| 3 | 4 | 5 | Worst |

| A | B | C | Type |
| 1 | 2 | 3 | Medium |

| A | B | C | Type |
| 1 | 5 | 20 | Worst|

我正在尝试创建一个分组箱线图,其中 3 种类型中的每个 A 都获得一个箱线图并组合在一起,B 和 C 也是如此

我不确定如何将所有这些数据帧连接在一起,以便我可以将它们发送到 seaborn catplot 函数中。似乎没有太多关于如何设置数据的文档。

最佳答案

首先用 concat 连接三个数据帧然后使用 seaborn 从结果数据框中生成箱线图

import seaborn as sns

# generate the new data frame
df4 = pd.concat([df1, df2, df3])

# Do the boxplot
sns.boxplot(data=df4, x='Type', y='A')

关于python - Seaborn 和 Pandas,分组箱线图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61325829/

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