我是靠谱客的博主 内向哈密瓜,这篇文章主要介绍数据分析处理(二),现在分享给大家,希望可以做个参考。

取出前十下单id及数量

jupyter导包

复制代码
1
2
3
4
import pandas as pd #导入pandas用于表格操作 import xlrd #导入xlrd用于获取一个表格里多个sheet from matplotlib import pyplot as plt#导入pyplot用于绘图

解决中文乱码问题

复制代码
1
2
3
4
5
#sans-serif就是无衬线字体,是一种通用字体族。 #常见的无衬线字体有 Trebuchet MS, Tahoma, Verdana, Arial, Helvetica, 中文的幼圆、隶书等等。 import matplotlib as mpl mpl.rcParams['font.sans-serif']=['SimHei'] #指定默认字体 SimHei为黑体

读取表格合并sheet(当知道sheet名时)

复制代码
1
2
3
4
5
6
table1=pd.read_excel('meal_order_detail.xlsx',sheet_name='meal_order_detail1') table2=pd.read_excel('meal_order_detail.xlsx',sheet_name='meal_order_detail2') table3=pd.read_excel('meal_order_detail.xlsx',sheet_name='meal_order_detail3') foodData=pd.concat([table1,table2,table3],axis=0,sort=False) foodData

取出数据

复制代码
1
2
3
4
5
6
7
order_foods=foodData['order_id'].value_counts() #求出所有菜品的名称及所对应的的数量 Y=order_foods.values[0:10] #取出数量 X=order_foods.index[0:10] #取出用户ID Y1=Y.tolist() print(Y1) print(X)

结果:[36, 29, 27, 27, 27, 26, 25, 24, 24, 24]
Int64Index([398, 1295, 582, 465, 1078, 1311, 1033, 426, 777, 769]dtype=‘int64’)
准备饼绘图间距数据

复制代码
1
2
3
4
new_array = np.zeros((1,10)) #相当一个1*10的矩阵(array)类型,但是没有值,只有框架,数据个数必须与饼的个数相同,而且这里只能写10, #不能写成(1,10)这样它会变为[[]]形式,我们只需要[]。 print(new_array)

结果:[[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]]
添加间距参数数据

复制代码
1
2
3
new_array[0] = 0.1 #赋值给框架每个值于0.1 print(new_array)

结果:[[0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1]]
转类型

复制代码
1
2
3
explode=new_array.tolist()[0] #转成list。 print(explode)

结果:[0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1]
展示

复制代码
1
2
3
4
plt.pie(Y1,labels=X,autopct='%.2f%%',shadow=False,explode=[0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1]) #Y1位置参数代表饼的成份,#labels为饼成份对象,shadow是阴影,True是有阴影,False是没有阴影,默认是False。explode是每个饼成分之间的间距 plt.show()

在这里插入图片描述

最后

以上就是内向哈密瓜最近收集整理的关于数据分析处理(二)的全部内容,更多相关数据分析处理(二)内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(54)

评论列表共有 0 条评论

立即
投稿
返回
顶部