import pandas as pd import numpy as np catering_sale = 'E:/data/catering_fish_congee.xls' # 餐饮数据 data = pd.read_excel(catering_sale,names=['date','sale']) # 读取数据,指定“日期”列为索引 # bins = [0,500,1000,1500,2000,2500,3000,3500,4000] bins = [0,800,1600,2400,3200,4000] # labels = ['[0,500)','[500,1000)','[1000,1500)','[1500,2000)', # '[2000,2500)','[2500,3000)','[3000,3500)','[3500,4000)'] labels = ['A','B','C','D','E'] data['sale分层'] = pd.cut(data.sale, bins, labels=labels) aggResult = data.groupby('sale分层').agg({'sale':'count'}) pAggResult = round(aggResult/aggResult.sum(), 2, ) * 100 print(data.describe()) import matplotlib.pyplot as plt plt.figure(figsize=(10,6)) # 设置图框大小尺寸 pAggResult['sale'].plot(kind='bar',width=0.8,fontsize=10) # 绘制频率直方图 plt.rcParams['font.sans-serif'] = ['SimHei'] # 用来正常显示中文标签 plt.title('2020310143026',fontsize=20) plt.show()
频率直方图:
import numpy as np import pandas as pd import matplotlib.pyplot as plt catering_sale = 'E:/data/catering_fish_congee.xls' data = pd.read_excel(catering_sale,names=['date','sale']) df = pd.DataFrame(data) df.plot.box(title="2020310143026") plt.grid(linestyle="--", alpha=0.3) plt.show()
箱型图:
import pandas as pd import numpy as np import matplotlib.pyplot as plt #解决中文乱码 plt.rcParams['font.sans-serif']=['SimHei'] #引入数据 df = pd.read_excel('E:/data/catering_dish_profit.xls') #设置画布大小 plt.figure(figsize=(10,6)) x = df['盈利'] #销售额 labels=df['菜品名'] #子类目(外标题) explode = [0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05] # 绘制饼图:半径为0.5,数值保留1位小数 plt.pie(x,labels=labels,autopct='%3.1f%%',labeldistance=1.02,startangle=90,textprops={'fontsize':12},explode=explode,shadow=True) plt.title('2020310143026',fontsize=20) plt.show()
饼图:
import pandas as pd import numpy as np catering_sale = 'E:/data/dish_sale.xls' # 餐饮数据 data = pd.read_excel(catering_sale,names=['月份','A部门','B部门','C部门']) # 读取数据,指定“日期”列为索引 print(data.describe()) import matplotlib.pyplot as plt x=data['月份'] y_data1=data['A部门'] y_data2=data['B部门'] y_data3=data['C部门'] plt.figure(figsize=(14,8)) # 设置图框大小尺寸 x_width = range(0,len(x)) x2_width = [i+0.3 for i in x_width] x3_width = [i+0.6 for i in x_width] plt.bar(x_width,y_data1,width=0.3,label="A部门",color="c") plt.bar(x2_width,y_data2,width=0.3,label="B部门",color="m") plt.bar(x3_width,y_data3,width=0.3,label="C部门",color="y") plt.xticks(range(0,12),x) plt.xlabel('月份') plt.title('2020310143026',fontsize=20) plt.rcParams['font.sans-serif'] = ['SimHei'] # 用来正常显示中文标签 plt.legend() plt.show()
直方图:
import matplotlib.pyplot as plt import pandas as pd import numpy as np catering_sale = 'E:/data/catering_fish_congee.xls' # 餐饮数据 data = pd.read_excel(catering_sale,names=['date','sale']) x=data['date'] y=data['sale'] plt.figure(figsize=(14,8)) # 设置图框大小尺寸 plt.plot(x,y,'bp') plt.xlabel('月份') plt.title('2020310143026',fontsize=20) plt.rcParams['font.sans-serif'] = ['SimHei'] # 用来正常显示中文标签 # plt.legend() plt.show()
散点图:
标签:plt,画图,sale,width,pd,import,data From: https://www.cnblogs.com/20020420zeng/p/17157252.html