python - Seaborn:使用箱线图导致内存不足

标签 python python-2.7 out-of-memory boxplot seaborn

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

最佳答案

交换 xy 列名:

import seaborn as sns
sns.boxplot(x="weight_cat" y="Height", data=data)

目前,您正在尝试创建一个包含不同高度值(即 24503)的箱线图的图表。

这对我有用你的数据:

enter image description here

编辑

如果你想水平显示你的箱线图,你可以使用 orient 参数来提供方向:

sns.boxplot(x='Height', y='weight_cat', data=data, orient='h')

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

关于python - Seaborn:使用箱线图导致内存不足,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36666562/

相关文章:

python - 如何解决已经在 python 中关闭的 zip 存档?

python - 使用 Python 查找文档频率

使用 VBA 导入文本文件时 Excel 内存不足警告

flutter - 使用预加载页面浏览播放 15 到 20 个视频后,我在 flutter 中遇到内存不足错误

python - Cython在所有Python脚本上引发相同的运行时错误

python - 在 Maya 中将着色器存储为 Python 变量

python - 将字母和数字组合在一起作为序数

python - 比较python中的日期

python - Anaconda:禁用提示更改

linux - 如何为 chrome 的 OOM Killer 设置内存限制?