我想为 1、2 和 3 weight_cat
值绘制三个箱线图(这些是它唯一具有的不同值)。这些箱线图应显示权重类别 (weight_cat
) 的依赖高度。
所以我有这样一个数据框:
print data.head(5)
Height Weight weight_cat
Index
1 65.78331 112.9925 1
2 71.51521 136.4873 2
3 69.39874 153.0269 3
4 68.21660 142.3354 2
5 67.78781 144.2971 2
下面的代码终于吃掉了我所有的 ram。这不正常,我相信:
Seaborn.boxplot(x="Height", y="weight_cat", data=data)
这里有什么问题?这是 manual 的链接.数据框的形状是 (25000,4)。这是指向 csv file 的链接.
这是获取相同数据的方法:
data = pd.read_csv('weights_heights.csv', index_col='Index')
def weight_category(weight):
newWeight = weight
if newWeight < 120:
return 1
if newWeight >= 150:
return 3
else:
return 2
data['weight_cat'] = data['Weight'].apply(weight_category)
最佳答案
交换 x
和 y
列名:
import seaborn as sns
sns.boxplot(x="weight_cat" y="Height", data=data)
目前,您正在尝试创建一个包含不同高度值(即 24503)的箱线图的图表。
这对我有用你的数据:
编辑
如果你想水平显示你的箱线图,你可以使用 orient
参数来提供方向:
sns.boxplot(x='Height', y='weight_cat', data=data, orient='h')
请注意,在这种情况下,x
和 y
标签被交换了(如您的问题)。
关于python - Seaborn:使用箱线图导致内存不足,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36666562/