pandas数据处理进阶

本文深入探讨pandas的统计分析,包括数值和非数值数据的统计,详细讲解时间数据的处理,如时间点和时间序列的转换,并介绍分组聚合、透视表与交叉表的应用。同时,通过具体案例展示如何利用pandas进行营业额和连锁超市数据分析。
摘要由CSDN通过智能技术生成

一、pandas的统计分析

1、关于pandas 的数值统计(统计detail 中的 单价的相关指标)

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("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())
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())
print("amounts 的极差:\n",detail.loc[:,'amounts'].ptp())
print("amounts 的标准差:\n",detail.loc[:,'amounts'].std())
print("amounts 的众数:\n",detail.loc[:,'amounts'].mode()) # 返回众数的数组
print("amounts 的众数:\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()

2、pandas对于非数值型数据的统计分析

   (1)对于dataframe转化数据类型,其他类型 转化为object类型

detail.loc[:,'amounts'] = detail.loc[:,'amounts'].astype('object')
 

  (2)类别型数据

detail.loc[:,'amounts'] = detail.loc[:,'amounts'].astype('category')

print("统计类别型数据的describe指标:\n",detail.loc[:, 'amounts'].describe())

(3)统计实例

#### 统计在detail中 最火的菜品以及卖出的份数
## 若白饭算菜
detail.loc[:, 'dishes_name'] = detail.loc[:, 'dishes_name'].astype
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值