【问题标题】:Error in display kurtosis and skewness on graph图表上显示峰度和偏度的错误
【发布时间】:2019-11-25 12:12:32
【问题描述】:

我在这个论坛中发现了一个代码,可以计算并在直方图上显示偏度和峰度。

这是我在情节中使用的代码:

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: 基于位置的索引只能有 [integer, integer 切片(包含起点,排除终点),类似列表 整数、布尔数组] 类型

我知道这里的问题是位置,可能是代码中显示 iloc 的部分,但我不知道如何解决它,我刚刚开始使用 python,所以解释越广泛,我的问题就越少'会有...

我的最终目标是调整这些图上的峰度和偏度

【问题讨论】:

    标签: python pandas histogram kurtosis


    【解决方案1】:

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

    尝试用for循环上的整个dataframe数据替换这个data['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')
    

    【讨论】:

    • 如果我只想为一个情节显示它?
    • 请验证我的回答,因为我已经向您解释了问题。
    • 请验证我的回答,因为我已经向您解释了问题。 @Reut
    猜你喜欢
    • 2017-02-16
    • 2019-04-01
    • 1970-01-01
    • 2016-11-14
    • 1970-01-01
    • 2020-04-16
    • 2013-03-28
    • 2011-06-27
    • 2023-03-06
    相关资源
    最近更新 更多