数据预处理

df['marital'] = df['marital'].astype('category') df['lending_rate3m'] = df['lending_rate3m'].astype('float') test['marital'] = test['marital'].astype('category') test['lending_rate3m'] = test['lending_rate3m'].astype('float')

数据可视化

p = figure(title="Marital vs Lending Rate 3m", x_axis_label='Marital', y_axis_label='Lending Rate 3m')

分类变量

categories = df['marital'].cat.categories.tolist() colors = ['#FF5733', '#FFC300', '#DAF7A6', '#C70039', '#900C3F'] color_mapper = dict(zip(categories, colors)) df['colors'] = df['marital'].map(color_mapper)

数值型变量

p.circle(x='marital', y='lending_rate3m', source=df, size=10, color='colors')

输出图像

output_file("marital_lending_rate3m.html") show(p

以下为python语言采用bokeh库一张图可视化分析marital 分类型和lending_rate3m 数值型from bokehplotting import figure showoutput_fileimport numpy as npimport pandas as pdimport pandasdf = pdread_csvrUsersfuchuanruoDesktop可视化作业实践

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

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