首页 > 其他分享 >第三章图3143

第三章图3143

时间:2023-03-13 20:57:46浏览次数:26  
标签:loc plt 第三章 plot sale 3143 statistics data

 

import pandas as pd
catering_sale="C:/Users/Lenovo/Desktop/catering_sale.xls"

 

data=pd.read_excel(catering_sale,index_col=u'日期')
print(data.describe())

 


import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus']=False
plt.figure()
p=data.boxplot(return_type='dict')
x=p['fliers'][0].get_xdata()
y=p['fliers'][0].get_ydata()
y.sort()

 

for i in range(len(x)):
if i>0:
plt.annotate(y[i],xy=(x[i],y[i]),xytext=(x[i]+0.05 -0.8/(y[i]-y[i-1]),y[i]))
else:
plt.annotate(y[i],xy=(x[i],y[i]),xytext=(x[i]+0.08,y[i]))
plt.title('学号3243')
plt.show()

 

 

# 代码3-3 捞起生鱼片的季度销售情况
import pandas as pd
import numpy as np
catering_sale = "C:/Users/Lenovo/Desktop/catering_fish_congee.xls" # 餐饮数据
data = pd.read_excel(catering_sale,names=['date','sale']) # 读取数据,指定“日期”列为索引

bins = [0,500,1000,1500,2000,2500,3000,3500,4000]
labels = ['[0,500)','[500,1000)','[1000,1500)','[1500,2000)',
'[2000,2500)','[2500,3000)','[3000,3500)','[3500,4000)']

data['sale分层'] = pd.cut(data.sale, bins, labels=labels)
print(data)
aggResult = data.groupby(by=['sale分层'])['sale'].agg({"count","count"})
print(aggResult)
pAggResult = round(aggResult/aggResult.sum(), 2, ) * 100
print(pAggResult)

import matplotlib.pyplot as plt
plt.figure(figsize=(10,6)) # 设置图框大小尺寸
pAggResult['count'].plot(kind='bar',width=0.6,fontsize=10) # 绘制频率直方图
plt.rcParams['font.sans-serif'] = ['SimHei'] # 用来正常显示中文标签
plt.title('学号3243,季度销售额频率分布直方图',fontsize=20)
plt.show()

 

 

import pandas as pd
import matplotlib.pyplot as plt
catering_dish_profit="C:/Users/Lenovo/Desktop/catering_dish_profit(1).xls"
data=pd.read_excel(catering_dish_profit)

x=data['盈利']
labels=data['菜品名']
plt.figure(figsize=(8,6))
plt.pie(x,labels=labels)
plt.rcParams['font.sans-serif']='SimHei'
plt.title('学号3124,菜品销售量分布(饼图)')
plt.axis('equal')
plt.show()

x=data['菜品名']
y=data['盈利']
plt.figure(figsize=(8,4))
plt.bar(x,y)
plt.rcParams['font.sans-serif']='SimHei'
plt.xlabel('菜品')
plt.ylabel('销量')
plt.title('学号3243,菜品销售量分布(条形图)')plt.show()

 

 

 

 

#部门之间销售金额比较
import pandas as pd
import matplotlib.pyplot as plt
data=pd.read_excel("C:/Users/Lenovo/Desktop/dish_sale(1).xls")
plt.figure(figsize=(8,4))
plt.plot(data['月份'],data['A部门'],color='green',label='A部门',marker='o')
plt.plot(data['月份'],data['B部门'],color='red',label='B部门',marker='s')
plt.plot(data['月份'],data['C部门'],color='skyblue',label='C部门',marker='x')
plt.legend()
plt.ylabel('销售额(万元)')
plt.title('学号3243,部门之间销售金额比较')
plt.show()

data=pd.read_excel("C:/Users/Lenovo/Desktop/dish_sale_b(1).xls")
plt.figure(figsize=(8,4))
plt.plot(data['月份'],data['2012年'],color='green',label='2012年',marker='o')
plt.plot(data['月份'],data['2013年'],color='red',label='2013年',marker='s')
plt.plot(data['月份'],data['2014年'],color='skyblue',label='2014年',marker='x')
plt.legend()
plt.ylabel('销售额(万元)')
plt.show()

 

 import pandas as pd
print("3243")
catering_sale="C:/Users/Lenovo/Desktop/catering_sale.xls"
data=pd.read_excel(catering_sale,index_col='日期')
data=data[(data['销量']>400)&(data['销量']<5000)]
statistics=data.describe()
statistics.loc['range']=statistics.loc['max']-statistics.loc['min']
statistics.loc['var']=statistics.loc['std']/statistics.loc['mean']
statistics.loc['dis']=statistics.loc['75%']-statistics.loc['25%']
print(statistics)

 

 

import pandas as pd
import matplotlib.pyplot as plt
df_normal=pd.read_excel("C:/Users/Lenovo/Desktop/user.xls")
plt.figure(figsize=(8,4))
plt.plot(df_normal["Date"],df_normal["Eletricity"])
plt.xlabel("日期")
x_major_locator=plt.MultipleLocator(7)
ax=plt.gca()
ax.xaxis.set_major_locator(x_major_locator)
plt.ylabel("每日电量")
plt.title("学号32434,正常用户电量趋势")
plt.rcParams['font.sans-serif']=['SimHei']
plt.show()

df_steal=pd.read_excel("C:/Users/Lenovo/Desktop/Steal user.xls")
plt.figure(figsize=(10,9))
plt.plot(df_steal["Date"],df_steal["Eletricity"])
plt.xlabel("日期")
plt.ylabel("日期")
x_major_locator=plt.MultipleLocator(7)
ax=plt.gca()
ax.xaxis.set_major_locator(x_major_locator)
plt.title("学号3243,窃电用户电量趋势")
plt.rcParams['font.sans-serif']=['SimHei']
plt.show()

 

标签:loc,plt,第三章,plot,sale,3143,statistics,data
From: https://www.cnblogs.com/wangnm/p/17212817.html

相关文章

  • 《高性能mysql》之性能分析(第三章)
    额外:吞吐量是性能优化的副产品作用:性能分析确定哪些子任务是优化目标,测量出响应时间花在哪分析MySQL查询:     慢查询日志:     ①安装使用教程......
  • 第三章 C语言:栈和队列
    一、栈特性:先进后出,顺序存储#include<stdio.h>#include<stdlib.h>#include<assert.h>#include<stdbool.h>#defineCAPACITY3//默认初识容量typedefintSD......
  • 以太网概念第三章:以太网系统
    本文直接转载自图灵社区:第3章以太网系统以太网系统由硬件和软件组成,通过软硬件的协作在计算机间传递电子数据。为了完成这项任务,以太网包含了一些基本的元素。熟知这......
  • MongoDB :第三章:MongoDB的数据类型与创建MongoDB数据库
    元数据数据库的信息是存储在集合中。它们使用了系统的命名空间:dbname.system.*在MongoDB数据库中名字空间.system.*是包含多种系统信息的特殊集合(Collection),如下:......
  • 第三章代码
    importpandasaspdcatering_sale="C:/Users/Lenovo/Desktop/catering_sale.xls"data=pd.read_excel(catering_sale,index_col=u'日期')print(data.describe())importm......
  • 第三章画图代码
    importpandasaspdcatering_sale="C:/Users/Lenovo/Desktop/catering_sale.xls"data=pd.read_excel(catering_sale,index_col=u'日期')print(data.describe())im......
  • 用Python画数据分析第三章的图
    importpandasaspdcatering_sale="C:/Users/Lenovo/Desktop/catering_sale.xls"data=pd.read_excel(catering_sale,index_col=u'日期')print(data.describe())importm......
  • 第三章图3124
    importpandasaspdcatering_sale="C:/Users/Lenovo/Desktop/catering_sale.xls"data=pd.read_excel(catering_sale,index_col=u'日期')print(data.describe())importm......
  • 第三章 半导体器件
    物体根据导电能力的强弱可分为导体、半导体和绝缘体三大类。半征半导体本征半导体是一种纯净的半导体晶体。常用的半导体材料是单晶硅(Si)和单晶锗(Ge)。半导体硅和锗都是4价元......
  • 用python画数据分析第三章的图
    importpandasaspdcatering_sale=(r'D:\sjfx\catering_sale.xls')data=pd.read_excel(catering_sale,index_col='日期')print(data.describe())  importmatplotli......