图形上显示峰度和偏度的错误

2024-09-28 01:33:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我在这个论坛上发现了一个代码,它假设计算并显示直方图上的偏度和峰度

这是我在绘图中使用的代码:

sns.distplot(data['HR90'], color="blue", bins=15, kde=True)
    ax.text(x=0.97, y=0.97, transform=ax.transAxes, s="Skewness: %f" % data.iloc[:,i].skew(),\
        fontweight='demibold', fontsize=10, verticalalignment='top', horizontalalignment='right',\
        backgroundcolor='white', color='xkcd:poo brown')
    ax.text(x=0.97, y=0.91, transform=ax.transAxes, s="Kurtosis: %f" % data.iloc[:,i].kurt(),\
        fontweight='demibold', fontsize=10, verticalalignment='top', horizontalalignment='right',\
        backgroundcolor='white', color='xkcd:dried blood')

但我犯了一个错误:

ValueError: Location based indexing can only have [integer, integer slice (START point is INCLUDED, END point is EXCLUDED), listlike of integers, boolean array] types

我理解这里的问题是位置,可能是代码中表示iloc的部分,但我不知道如何修复它,我刚刚开始使用python,因此解释越广泛,我遇到的问题就越少

我的最终目标是在这些图上显示峰度和偏度


Tags: 代码textdatatoptransformaxcolor峰度
1条回答
网友
1楼 · 发布于 2024-09-28 01:33:09

我认为问题在于这个数据['HR90']已经是一列了。 您需要在数据框的所有列上绘制图

尝试为for循环上的整个数据帧数据替换此数据['HR90'] 你好像在做什么

sns.distplot(data['HR90'], color="blue", bins=15, kde=True)
    ax.text(x=0.97, y=0.97, transform=ax.transAxes, s="Skewness: %f" % data['HR90'].skew(),\
        fontweight='demibold', fontsize=10, verticalalignment='top', horizontalalignment='right',\
        backgroundcolor='white', color='xkcd:poo brown')
    ax.text(x=0.97, y=0.91, transform=ax.transAxes, s="Kurtosis: %f" % data['HR90'].kurt(),\
        fontweight='demibold', fontsize=10, verticalalignment='top', horizontalalignment='right',\
        backgroundcolor='white', color='xkcd:dried blood')

相关问题 更多 >

    热门问题