如何使用Seaborn选择特定行来绘制箱形图?
索引 | 变量 | 值 |
---|---|---|
0 | a | 向上 |
1 | A | 下向 |
2 | A | 下向 |
3 | A | 上3 a上升 |
4 | B | 下降 |
5 | B | 上5 B下降 |
6 | B | 下降 |
7 | B | 上升 |
8 | C | 向上 |
9 | C | 向上 |
10 | C | 下 |
10 c下降11 c下12 | d | 上 |
12 | d | 上 |
12 | d上13 d | 下降 |
14 | d | 下降 |
15 | d | 例如 |
,我想通过使用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 )。
index | variable | value |
---|---|---|
0 | A | up |
1 | A | down |
2 | A | up |
3 | A | up |
4 | B | down |
5 | B | up |
6 | B | down |
7 | B | up |
8 | C | up |
9 | C | up |
10 | C | down |
11 | C | down |
12 | D | up |
13 | D | down |
14 | D | down |
15 | D | up |
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从变量中选择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)