python如何应用于数据的基础统计分析
python如何应用于数据的基础统计分析
使用实例:分别统计Excel中蛋白质和固形物数据
1、建立根据任务要求分别统计蛋白质和固形物的自定义函数(方法)
defprod_describe(data,classify,category,remove_col):
desc=data.groupby([classify])[category].describe()
desc.drop(columns=remove_col,axis=1,inplace=True)
#Range(极差)=max-min
desc["极差"]=desc["max"]-desc["min"]
#更新统计数据的列名称(英文--》中文)
desc=desc.rename(columns={"count":"样品数量",
"mean":"平均值",
"std":"标准偏差",
"min":"最小值",
"max":"值"})
desc=desc.sort_values(by=["样品数量"],axis=0,ascending=False)
returndesc
#由于报告不需要分位数的统计量,故删除这些字段[25%,50%,70%]
remove_col=["25%","50%","75%"]
2、关键参数的赋值
classify="产品"
category1="蛋白质"
category2="固形物"
data=data_prep.copy()
3、实现根据产品名称分别对蛋白质和固形物进行统计
category1_desc=prod_describe(data,classify,category1,remove_col)
category2_desc=prod_describe(data,classify,category2,remove_col)
4、将两种统计结果汇总在一起,写入Excel文件中并保存
category2])
file="d:/test/Summary/Data_Statistics.xlsx"
result.to_excel(file,sheet_name="Statistics")
print("已经全部完成,请检查!")
以上就是python如何应用于数据的基础统计分析,希望能对大家有所帮助。更多Python学习教程请关注IT培训机构:千锋教育。

相关推荐HOT
更多>>
python函数标注是什么
python函数标注是什么在参数的使用方法中,还有一种解包的情况是需要我们掌握的。比如,将列表或者字典的值转换为函数的参数,就需要用到参数解...详情>>
2023-11-14 14:13:35
python正负索引的使用
python正负索引的使用本文教程操作环境:windows7系统、Python3.9.1,DELLG3电脑。1、说明使用正索引(从左至右)、负索引(从右至左)访问元素,时...详情>>
2023-11-14 13:45:04
python垃圾回收的机制过程
python垃圾回收的机制过程本文教程操作环境:windows7系统、Python3.9.1,DELLG3电脑。1、步骤(1)收集所有容器对象(list,dict,tuple,customClas...详情>>
2023-11-14 13:05:15
pythontry语句的执行原理
pythontry语句的执行原理1、原理分析(1)执行try子句(try和except关键字之间的多行语句)。(2)如果没有异常发生,则跳过except子句并完成try语句...详情>>
2023-11-14 09:37:35热门推荐
技术干货






