根据数据分析与挖掘实战这本书写程序,小白上路,仅供参考,大神勿喷


数据集样式:

帕累托图


问题描述:对菜品数据做帕累托图

python3代码实现:

"""
codinng:utf-8
菜品盈利数据 怕累托图
"""
"""导入数据库"""
from __future__ import print_function
import pandas as pd

"""初始化参数"""
dish_profit = 'catering_dish_profit.xls'#餐饮菜品的盈利数据
data = pd.read_excel(dish_profit,index_col=u'菜品名')
#data.pop(u'菜品ID')#将菜品ID从数据列表中剔除
data = data[u'盈利'].copy()
data_new=data.sort_values(ascending = False)
#data_new=data.sort_values(by = u'盈利',ascending = False)
#print(data_new)

import  matplotlib.pyplot as plt#导入图像库
plt.rcParams['font.sans-serif'] = ['SimHei']#用来显示正常的中文标签
plt.rcParams['axes.unicode_minus'] = False#用来显示正常的负号

plt.figure()
data_new.plot(kind ='bar')#绘制条形图
plt.ylabel(u'盈利(元)')
p = 1.0*data_new.cumsum()/data_new.sum()
p.plot(color ='r',secondary_y = True,style = '-o',linewidth = 2)
plt.annotate(format(p[6],'.4%'), xy = (6,p[6]),xytext = (6*0.9,p[6]*0.9),
             arrowprops = dict(arrowstyle="->",connectionstyle = "arc3,rad=.2"))
#添加注释,即85%处的标记,这里包括了指定箭头的样式
plt.ylabel(u'盈利(比例)')
plt.show()

运行结果:

帕累托图

相关文章:

  • 2021-11-06
  • 2021-06-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-04
  • 2022-12-23
猜你喜欢
  • 2021-12-03
  • 2021-09-16
  • 2021-10-29
  • 2022-12-23
  • 2021-07-25
  • 2021-07-20
相关资源
相似解决方案