首页 > 解决方案 > “str”对象在调用函数绘制直方图时没有属性“hist”错误

问题描述

通过将数据框和列作为参数传递来绘制直方图来创建函数。但是,在调用此函数时获取“str”对象没有属性“hist”错误

def histogram1(df,c1,c2):
    plot= df.hist(column='c1', by='c2',bins=25, grid=False, figsize=(20,5), layout=(1,2), sharex=True, color='#86bf91', zorder=2, rwidth=0.9)
    for i,x in enumerate(plot):
        x.set_xlabel('c1', labelpad=20, weight='bold', size=12)
        x.set_ylabel('Frequency', labelpad=20, weight='bold', size=12)
    return
histogram1('dataset','avg_glucose_level','stroke')

标签: pythonfunction

解决方案


推荐阅读