import pandas as pd
from pyecharts.charts import Bar
from pyecharts import options as opts
import xlrd
####读取excel 需要插件库 xlrd pip install xlrd
df_tb = pd.read_excel('./day1/hw.xlsx') ####读取excel表
store_location_num_tuple = df_tb.location.value_counts().items() #####读取hw.xlsx文档中location的值次数
# for i in store_location_num_tuple:
# print(i)
store_location_num = (dict(store_location_num_tuple))
####绘图
bar = (
Bar()
.add_xaxis(list(store_location_num.keys()))
.add_yaxis('分布图',list(store_location_num.values())) ####
.set_global_opts(
title_opts=opts.TitleOpts(title='产品使用情况'),
xaxis_opts=opts.AxisOpts(name='产品名字'),
yaxis_opts=opts.AxisOpts(name='数量')
)
)
# bar.render_notebook() ##输出分布图
bar.render('分布图.html') ###输出html文件分布图
相关