欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

python数据分析|肥胖指数BMI计算

程序员文章站 2022-05-16 09:10:54
...
import numpy as np
import pandas as pd
from pyecharts.charts import Bar,Grid
from pyecharts import options as opts
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
font = FontProperties(fname=r"C:\\WINDOWS\\Fonts\\simsun.ttc", size=10)
data=pd.read_csv(r'D:\pycharm\身高体重.csv',encoding='gbk')

listbins=[0,18.4,23.9,27.9,55]
listlables=['偏瘦','正常','过重','肥胖']
dcut=pd.cut(data['BMI'],bins=listbins,right=False,labels=listlables)
dcutnum=dcut.value_counts(sort=False)
data['BMI分组']=dcut.values
bar = Bar(init_opts=opts.InitOpts(width='2000px',height="1000px"))
bar.add_xaxis(listlables)
bar.add_yaxis("BMI",dcutnum,category_gap='30%',label_opts=opts.LabelOpts(position='top'))
bar.set_global_opts(title_opts=opts.TitleOpts(title="居民BMI"))
bar.render()

python数据分析|肥胖指数BMI计算

相关标签: 2019