Seaborn:使用箱线图导致 运行 内存不足

Seaborn: using boxplot cause running out of memory

我想为 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

下面的代码终于吃光了我所有的内存。这不正常,我相信:

Seaborn.boxplot(x="Height", y="weight_cat", data=data)

这里有什么问题?这是 link 到 manual. Shape of the dataframe is (25000,4). This the link to the 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)

交换 xy 列名称:

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')

请注意,在这种情况下,xy 标签被交换了(如您的问题)。