数据清洗

df.dropna(inplace=True) test.dropna(inplace=True)

统计有/无房贷违约比例

housing_default = df.groupby(['housing', 'default']).size().reset_index(name='count') housing_default['percent'] = housing_default['count'] / housing_default['count'].sum()

绘制条形图

p = figure(x_range=housing_default['housing'] + housing_default['default'], plot_height=350, title="Housing and Default", toolbar_location=None, tools="")

p.vbar(x=housing_default['housing'] + housing_default['default'], top=housing_default['percent'], width=0.9)

p.xgrid.grid_line_color = None p.y_range.start = 0 p.y_range.end = 0.7 p.legend.orientation = "horizontal" p.legend.location = "top_center"

输出HTML文件

output_file("housing_default.html")

显示图形

show(p

使用python的bokeh库对housing是否有房贷和default信用卡是否违约条形图判断有房贷是否违约和无房贷是否违约比例进行可视化分析布局合理from bokehplotting import figure showoutput_fileimport numpy as npimport pandas as pdimport pandasdf = pdread_csvrUsersfuchu

原文地址: http://www.cveoy.top/t/topic/fdzh 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录