Python statistics 模块

简介: Python statistics 模块

Python statistics 是标准库中的一个模块,模块提供了许多基本统计计算的函数。

statistics 模块是在 Python 3.4 版本中新增加的,可以帮助我们分析和计算数据集的统计特征。

要使用 statistics 函数必须先导入:

import statistics

查看 statistics 模块中的内容:

>>> import statistics

>>> dir(statistics)

['Counter', 'Decimal', 'Fraction', 'NormalDist', 'StatisticsError', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_coerce', '_convert', '_exact_ratio', '_fail_neg', '_find_lteq', '_find_rteq', '_isfinite', '_normal_dist_inv_cdf', '_ss', '_sum', 'bisect_left', 'bisect_right', 'erf', 'exp', 'fabs', 'fmean', 'fsum', 'geometric_mean', 'groupby', 'harmonic_mean', 'hypot', 'itemgetter', 'log', 'math', 'mean', 'median', 'median_grouped', 'median_high', 'median_low', 'mode', 'multimode', 'numbers', 'pstdev', 'pvariance', 'quantiles', 'random', 'sqrt', 'stdev', 'tau', 'variance']

math 模块方法

方法 描述
statistics.harmonic_mean() 计算给定数据集的调和平均值。
statistics.mean() 计算数据集的平均值
statistics.median() 计算数据集的中位数
statistics.median_grouped() 计算给定分组数据集的分组中位数
statistics.median_high() 计算给定数据集的高位中位数
statistics.median_low() 计算给定数据集的低位中位数。
statistics.mode() 算数据集的众数(出现频率最高的值)
statistics.pstdev() 计算给定数据集的样本标准偏差
statistics.stdev() 计算数据集的标准差
statistics.pvariance() 计算给定数据集的样本方差
statistics.variance() 计算数据集的方差
statistics.quantiles() 计算数据集的分位数,可指定分位数的数量(默认为四分位数)
相关文章
|
3天前
|
XML 数据格式 Python
Python的`import`用于加载模块,基础形式是`import module`,全量导入
【6月更文挑战第23天】Python的`import`用于加载模块,基础形式是`import module`,全量导入;`from module import name`选择性导入部分,减少命名空间污染;`from module import *`导入所有(不推荐),易引发冲突。别名导入如`from math import sqrt as square_root`可避免冲突。包导入用`.`,如`import xml.etree.ElementTree as ET`。
23 8
|
3天前
|
XML 数据格式 Python
在Python中,导入其他模块是通过使用import语句完成的
在Python中导入模块涉及`import`语句的不同用法:1) `import math`导入整个标准库;2) `from math import sqrt`导入单个函数;3) `import numpy as np`使用别名;4) `from random import *`导入所有(不推荐);5) `import xml.etree.ElementTree as ET`导入子模块;6) 使用`importlib.import_module()`延迟导入;7) `from .module import func`导入相对路径模块,需管理`sys.path`。
24 6
|
2天前
|
算法 数据安全/隐私保护 开发者
Python logger模块详细讲解
Python logger模块详细讲解
|
3天前
|
Python
Python的`os`模块核心功能概述:通过`os.getcwd()`获取
【6月更文挑战第23天】Python的`os`模块核心功能概述:通过`os.getcwd()`获取、`os.chdir()`改变工作目录;使用`os.mkdir()`, `os.makedirs()`创建目录,`os.rmdir()`, `os.removedirs()`删除;`os.rename()`, `os.renames()`重命名文件或目录;`os.remove()`删除文件;`os.listdir()`列出目录内容;`os.path.exists()`, `os.path.isfile()`, `os.path.isdir()`检查路径;`os.stat()`获取文件属性。
14 4
|
3天前
|
XML 数据格式 Python
Python模块导入包括:`import math`导入标准库
【6月更文挑战第23天】Python模块导入包括:`import math`导入标准库,`from math import sqrt`导入单个函数,`import numpy as np`给模块取别名,`from random import *`导入所有(不推荐),`import xml.etree.ElementTree as ET`导入子模块,`import_module('pandas')`按需导入,和使用相对路径如`from .module import func`处理项目结构。记得调整`sys.path`以包含自定义模块路径。
15 4
|
2天前
|
Linux Python
Python- jinja2模块详解
Python- jinja2模块详解
|
8天前
|
Shell Python
python中模块对象__file__
【6月更文挑战第12天】
18 8
|
7天前
|
JSON Java API
Python教程:一文了解Python requests模块
Python 中的 requests 模块是一个简洁而强大的 HTTP 库,用于向 Web 服务器发送 HTTP 请求和处理响应。它让开发者能够更轻松地与网络资源进行交互,包括发送 GET、POST、PUT、DELETE 等类型的请求,并处理返回的数据。
37 6
|
8天前
|
Python
python中模块对象__name__
【6月更文挑战第12天】
21 7
|
7天前
|
Python
Python中的模块对象__package__
【6月更文挑战第13天】
14 5