python - “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')
解决方案
推荐阅读
- python - 如何使用自定义 geojson 文件来绘制带有 plotly 的库地图?
- python - 将 DataFrame 转换为 Dictionary 的函数
- ag-grid - 如何在ag-grid中删除隐藏字段从导出到excel
- asp.net-core - 有没有办法渲染位于另一个项目中的剃刀视图
- nix - nix-shell 无法更改语言环境警告
- javascript - Onclick按钮不调用django中的js函数
- python - 使用 dataframe2 (pandas, python) 中设置的条件从 dataframe1 中提取值
- html - 如何在 ReactJS 中解释任何类型的 HTML 包装容器(div,...)?
- php - php和mysqli使用ID显示文章
- ios - 就性能而言,在多个地方调用捆绑构造函数是否昂贵?