数据分析pandas属性实现统计分析
import pandas as pd#加载数据 detail = pd.read_excel("./meal_order_detail.xlsx") print("detail :\n",detail)print("detail 的列索引名称:\n",detail.columns) print("detail 的形状:\n",detail.shape) print("detail 数据类型:\n",detail.dtypes) print('detail数据类型:\n',detail.dtypes)#返回各列的数据类型# print("*"*80)# 关于pandas 的数值统计 # 统计detail 中的 单价的相关指标 print("amounts 的最大值:\n",detail.loc[:,'amounts'].max())# print("amounts 的最小值:\n",detail.loc[:,'amounts'].min()) print("amounts 的均值:\n",detail.loc[:,'amounts'].mean()) print("amounts 的中位数:\n",detail.loc[:,'amounts'].median()) print("amounts 的方差:\n",detail.loc[:,'amounts'].var())#var方差 print("amounts 的describe:\n",detail.loc[:,'amounts'].describe()) #对于两列的统计结果 print("amounts 的describe:\n",detail.loc[:,['counts','amounts']].describe()) print("amounts 的describe:\n",detail.loc[:,['counts','amounts']].describe()) print("amounts 的describe:\n",detail.loc[:,'amounts'].describe()) print("amounts 的describe:\n",detail.loc[:,'counts'].describe()) #describe对于数值型数据返回count总数、mean均值、std标准差、min最小值、3个四分线数据、max最大值 print("amounts 的极差:\n",detail.loc[:,'amounts'].ptp())#方差 print("amounts 的标准差:\n",detail.loc[:,'amounts'].std()) print("amounts 的众数:\n",detail.loc[:,'amounts'].mode()) # 返回众数的数组 print("counts 的众数:\n",detail.loc[:,'counts'].mode()) # 返回众数的数组 print("amounts 的非空值的数目:\n",detail.loc[:,'amounts'].count()) print("amounts 的最大值的位置:\n",detail.loc[:,'amounts'].idxmax()) # np.argmax() print("amounts 的最小值的位置:\n",detail.loc[:,'amounts'].idxmin()) # np.argmin() print("*"*80) # pandas对于非数值型数据的统计分析,对于dataframe转化数据类型 #1、其他类型(非数值型数据,非类别型数据,即顺序数据)转化为object类型 detail.loc[:,'amounts'] = detail.loc[:,'amounts'].astype('object') detail.loc[:,'amounts'] = detail.loc[:,'amounts'].astype('category') # 2、类别型数据转化为category类型category,种类分类手动创建排序是静态的 print(detail.dtypes) print("统计类别型数据的describe指标:\n",detail.loc[:, 'amounts'].describe()) #统计类别型数据的describe返回数量count、去重后的数量unique、众数top、众数的数量freq #unique独特的,独一无二的;top顶部顶端;freq频数 #unique独特的,独一无二的;top顶部顶端;freq频数 # 1、在detail中 哪些菜品最火?菜品卖出了多少份? # 白饭算菜 detail.loc[:,'dishes_name'] = detail.loc[:,'dishes_name'].astype('category') print("按照dishes_name统计描述信息:\n",detail.loc[:,'dishes_name'].describe())# 白饭不算菜 ---把白饭删除,再统计 #drop labels ---行的名称, axis =0,inplace = True # 行的名称??? 怎么获取----bool值 # 定位到白饭的行 bool_id = detail.loc[:,'dishes_name'] == '白饭/大碗' # # # 进行 获取行名称 index = detail.loc[bool_id,:].index # # # 进行删除 detail.drop(labels=index,axis=0,inplace=True) # # # 在进行转化类型 detail.loc[:,'dishes_name'] = detail.loc[:,'dishes_name'].astype('category') # # # 在进行统计描述信息 print("按照dishes_name统计描述信息:\n",detail.loc[:,'dishes_name'].describe())# 看 在detail 中那个订单点的菜最多,点了多少份菜? # 将 order_id 转化为类别型数据 ,再 进行describe detail.loc[:,'order_id'] = detail.loc[:,'order_id'].astype("category") # # 统计描述 print("按照order_id统计描述信息为:\n",detail.loc[:,'order_id'].describe())
数据分析pandas属性实现统计分析相关推荐
- python数据分析df_Python数据分析pandas入门!(附数据分析资料)
Python数据分析pandas入门!(附数据分析资料) 1.pandas数据结构之DataFrame+ 这是小编准备的python数据分析资料!进群:700341555即可获取! Python数据分 ...
- 数据分析---pandas(一)
活动地址:CSDN21天学习挑战赛 数据分析---pandas Pandas基本介绍 Pandas安装和引用 Pandas 基本数据结构 Pandas库的series类型 索引(数据的行标签) 值 切 ...
- Python数据分析——Pandas基础:dt.datetime与pivot_table()数据透视表
系列文章目录 Chapter 1:创建与探索DF.排序.子集化:Python数据分析--Pandas基础入门+代码(一) Chapter 2:聚合函数,groupby,统计分析:Python数据分析- ...
- python 数据分析模块_Python数据分析pandas模块用法实例详解
本文实例讲述了Python数据分析pandas模块用法.分享给大家供大家参考,具体如下: pandas pandas10分钟入门,可以查看官网:10 minutes to pandas 也可以查看更复 ...
- Python数据分析实战:降雨量统计分析报告分析
本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,如有问题请及时联系我们以作处理. 以下文章来源于菜J学Python ,作者小小明 最近遇到一个有点烧脑的需求,其实也不算烧pytho ...
- pandas dataframe column_Python数据分析——Pandas 教程(下)
Python数据分析--Pandas 教程(上) 上节,我们讲了 Pandas 基本的数据加载与检索,这节我们讲讲如何进行数据比较. Pandas系列对象 在 Pandas 中我们获取指定列的数据有多 ...
- pandas pivot 计算占比_数据分析Pandas 基础(二)
推荐阅读:数据分析--Pandas 基础(一) 上一节课介绍了 Pandas 的基本用法,这一章节我们通过对 "泰坦尼克号" 幸存者进行数据分析,来进一步的学习 pandas. t ...
- Python数据分析pandas之分组统计透视表
Python数据分析pandas之分组统计透视表 数据聚合统计 Padans里的聚合统计即是应用分组的方法对数据框进行聚合统计,常见的有min(最小).max(最大).avg(平均值).sum(求和) ...
- Python数据分析pandas之数据拼接与连接
Python数据分析pandas之数据拼接与连接 数据拼接处理 数据拼接处理指的是numpy.pandas里对数据的拼接.连接.合并等多种方法的概称.有时我们处理的数据会分很多步骤,而中间或者最终的结 ...
最新文章
- 运维想吃透监控系统,就这一篇足够了
- MPB:亚热带生态所谭支良、焦金真等-​反刍动物瘤胃样品采集与保存
- 连接远程ms sql server 2000企业版时出现错误:10061的解决方法
- C#显示百度地图API
- Egit Patch
- Android v4、v7、v13 的区别
- C语言创建一个节点Node(附完整源码)
- u盘复制不进去东西_确认过眼神,是电脑小白的福音!U启动U盘启动盘制作工具...
- 反射,System.Type类
- 构造AlertDialog弹出框,根据量值实现然用户选择列表。
- 关于python pandas read_csv的理解
- 最长上升子序列(LIS)题目合集
- flink的jar包和服务器的包冲突解决方案
- 关于博弈论的硬币问题
- 快速集成 iMessage(下)
- php 解压zip/rar
- 怎么解c语言逆向编码,逆向还原C语言代码 练习1
- 2021-11-05 springMVC 错误:org.springframework.http.converter.HttpMessageNotWritableException No conve
- iphone解锁那点事 (一)
- 面试磕磕碰碰,辛得蚂蚁高级工程师的技术笔记指导,终获P7岗offer