Thief of Wealth

def plot_count(feature, title, df, size=1):

    f,ax = plt.subplots(1,1,figsize=(4*size, 4))

    total = float( len(df) )

    g = sns.countplot(df[feature], order=df[feature].value_counts().index[:30], palette='Set3')

    g.set_title(F"Number and percentage of {title}")

    

    if( size > 2 ):

        plt.xticks(rotation=90, size=8)

    for p in ax.patches:

        height = p.get_height()

        ax.text(p.get_x() + p.get_width()/2., height + 3,

               '{:1.2f}%'.format(100*height/total),

                ha="center") 

        plt.show()



사용: plot_count('feature', '제목', df=train_identity_df, size=4)

profile on loading

Loading...