数据
一份关于保险的数据:链接在此。
数据描述
- age:年龄
- sex:性别
- bmi:体重指数(BMI)是基于身高和体重的体脂指标
- children:孩子个数
- smoker:是否吸烟
- region:区位
- charges:收费
预处理
import numpy as np
import pandas as pd
from bokeh.io import output_file, show, output_notebook, push_notebook
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource, HoverTool # Dataframe处理,hover组件
from bokeh.layouts import row, column, gridplot #布局相关部件
from bokeh.models.widgets import Tabs, Panel
from bokeh.palettes import Spectral6 # 导入colormap
from bokeh.transform import linear_cmap
from bokeh.io import export_png # 保存为png
import warnings
output_notebook()
warnings.filterwarnings('ignore')
# 数据导入
insurance = pd.read_csv('insurance.csv')
insurance.head()
# 查看数据类型
insurance.dtypes
# 查看缺失值, 没有缺失值
insurance.isna().sum()
# 数据描述
insurance.describe(include='all')
没有缺失值
Bokeh
Bokeh (Bokeh.js) 是一个 Python 交互式可视化库,支持现代化 Web 浏览器,提供非常完美的展示功能。Bokeh 的目标是使用 D3.js 样式提供优雅,简洁新颖的图形化风格,同时提供大型数据集的高性能交互功能。Boken 可以快速的创建交互式的绘图,仪表盘和数据应用。
条形图
# 获取年龄分布
age = insurance.sort_values('age').age.value_counts(sort=False