Reut
Reut

Reputation: 1592

Error in display kurtosis and skewness on graph

I have found in this forum a code that suppose to calcualte and display the skewness and kurtosis on a histogram.

This is the code as I have used on my plot:

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

but I get with this an error:

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

I understand the problem here is the location and probably the part of the code that says iloc but I don't know how to fix it, I have just started to work with python so the broader the explaination the less questions I'll have...

My end goal is to diaply the kurtosis and the skewness on those graphs

Upvotes: 0

Views: 304

Answers (1)

Borja_042
Borja_042

Reputation: 1071

I think the problem is that this data['HR90'] is already a column. And you want to make the plots over all columns of the dataframe.

Try to replace this data['HR90'] for the entire dataframe data on the for loop you seem to be doing.

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

Upvotes: 1

Related Questions