如何使用Seaborn选择特定行来绘制箱形图?

发布于 2025-01-30 19:13:15 字数 1191 浏览 4 评论 0原文

索引变量
0a向上
1A下向
2A下向
3A上3 a上升
4B下降
5B上5 B下降
6B下降
7B上升
8C向上
9C向上
10C
10 c下降11 c下12d
12d
12d上13 d下降
14d下降
15d例如

,我想通过使用seaborn在(variable = a and variable = b)中显示值来绘制一个箱形图。我该如何解决?

和以前一样,行表包含属性{“ variablea”,“ variableb”,“ variablec”,“ variabled”,“ value”},

以便我可以使用: sns.boxplot(x = df [“ variablea”],y = df [“ variableb”,order = [“ up”,“ down”,“ down”])

,现在我得到了一个熔体表(tidy datayframe )。

indexvariablevalue
0Aup
1Adown
2Aup
3Aup
4Bdown
5Bup
6Bdown
7Bup
8Cup
9Cup
10Cdown
11Cdown
12Dup
13Ddown
14Ddown
15Dup

For example, I want to draw a boxplot by using seaborn to show values in (variable =A and variable=B). How can I solve it?

AS before, the row table contain attributes{"variableA", "variableB","variableC","variableD","value"}

so I can use :
sns.boxplot(x=df["variableA"],y=df["variableB],order=["up","down"])

And now I got a melt table(tidy dataframe). How to draw the same picture?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凯凯我们等你回来 2025-02-06 19:13:15

从变量中选择b和a

您可以通过df.loc [(df.variable ==“ a”)& 。 (df.variable ==“ b”)]

然后通过:

df_t = df.loc [(df.variable ==“ a”)| (df.variable ==“ b”)]。t

然后sns:

sns.boxplot(x ='variable',y ='value',data = df_t)

You can select B and A from variable by

df.loc[(df.variable == "A") & (df.variable == "B")]

Then Transpose the df by:

df_T = df.loc[(df.variable == "A") | (df.variable == "B")].T

Then sns:

sns.boxplot(x='variable', y = 'value', data = df_T)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文