python stdev

Hey, folks! In continuation of our series on Python statistical functions, today we will be unveiling standard deviation using the Python stdev() method.

嘿伙计! 在我们的Python统计函数系列的继续中,今天我们将使用Python stdev()方法公开标准差

Standard deviation is a statistical entity that represents the variation in the data i.e. it depicts the deviation of data values from the center value (the mean of the data).

标准偏差是表示数据变化的统计实体,即,它描述了数据值与中心值(数据的平均值)的偏差。

Usually, standard deviation is calculated using the below formula–

通常,使用以下公式计算标准差–

Standard Deviation = (Variance)^1/2

Standard Deviation = (Variance)^1/2

Now, let us start with the implementation and calculation of Standard Deviation using Python in-built function.

现在,让我们开始使用Python内置函数来实现和计算标准偏差。



Python stdev()函数入门 (Getting started with Python stdev() function)

Python statistics module contains various in-built functions to perform the data analysis and other statistical functions. The statistics.stdev() function is used to calculate the standard deviation of the passed data values to the function as argument.

Python statistics module包含各种内置函数来执行数据分析和其他统计函数。 statistics.stdev() function用于计算作为参数传递给该函数的数据值的标准偏差。

Syntax:

句法:


statistics.stdev(data)

Example:

范例


import statistics
data = range(1,10)res_std = statistics.stdev(data)
print(res_std)

In the above example, we have created data of numbers from 1-10 using the range() function. Further, we apply the stdev() function to evaluate the standard deviation of the data values.

在上面的示例中,我们使用range()函数创建了1-10之间的数字数据。 此外,我们应用stdev()函数来评估数据值的标准偏差。

Output:

输出:


2.7386127875258306


NumPy模块的Python标准偏差 (Python standard deviation with NumPy module)

Python NumPy module converts the data elements into an array form to perform numeric manipulations on it.

Python NumPy模块将数据元素转换为数组形式以对其执行数字操作。

Further, numpy.std() function can be used to calculate the standard deviation of all the data values present in the NumPy array.

此外, numpy.std() function可用于计算NumPy数组中存在的所有数据值的标准偏差。

Syntax:

句法:


numpy.std(data)

We need to import the NumPy module into the Python environment to get access to the in-built functions of the same using the below code–

我们需要将NumPy模块导入Python环境中,以使用以下代码访问该模块的内置函数–


import numpy

Example:

例:


import numpy as np
import pandas as pd
data = np.arange(1,30)
res_std = np.std(data)
print(res_std)

In the above example, we have generated an array of elements from 1-30 using numpy.arange() function. After which, we pass the array to the numpy.std() function to calculate the standard deviation of the array elements.

在上面的示例中,我们使用numpy.arange() function从1到30生成了一个元素数组。 之后,我们将数组传递给numpy.std() function以计算数组元素的标准偏差。

Output:

输出:


8.366600265340756


Pandas模块的Python标准差 (Python standard deviation with Pandas module)

Python Pandas module converts the data values into a DataFrame and helps us analyse and work with huge datasets. The pandas.DataFrame.std() function is used to calculate the standard deviation of the data column values of a particular DataFrame.

Python Pandas模块将数据值转换为DataFrame,并帮助我们分析和使用庞大的数据集。 pandas.DataFrame.std()函数用于计算特定DataFrame的数据列值的标准偏差。

Syntax:

句法:


pandas.DataFrame.std()

Example 1:

范例1:


import numpy as np
import pandas as pd
data = np.arange(1,10)
df = pd.DataFrame(data)
res_std = df.std()
print(res_std)

In the above example, we have converted a NumPy array into a DataFrame and the applied the DataFrame.std() function to get the standard deviation of the data values.

在上面的示例中,我们将NumPy数组转换为DataFrame并应用了DataFrame.std() function以获取数据值的标准偏差。

Output:

输出:


0    2.738613
dtype: float64

Example 2:

范例2:


import pandas as pd
import seaborn as sns
import matplotlib.pyplot as pltdata = pd.read_csv("C:/mtcars.csv")
res_std = data['qsec'].std()
print(res_std)

In the above example, we have used a dataset and calculated the standard deviation of the data column ‘qsec’ using the DataFrame.std() function.

在上面的示例中,我们使用了数据集,并使用DataFrame.std()函数计算了数据列'qsec'的标准差。

Input Dataset:

输入数据集

MTCARS DatasetMTCARS数据集

Output:

输出:


1.7869432360968431


结论 (Conclusion)

Thus, in this article, we have understood the working of Python stdev() function along with NumPy and Pandas module.

因此,在本文中,我们了解了Python stdev()函数以及NumPy和Pandas模块的工作。



参考资料 (References)

  • Python stdev() function — Official DocumentationPython stdev()函数-官方文档

翻译自: https://www.journaldev.com/39575/python-stdev-function

python stdev

python stdev_Python stdev()函数的详细指南相关推荐

  1. python 如何定义函数——基础详细

    函数 函数的概念 如果在开发程序时,需要某块代码多次,但是为了编写代码的效率以及代码的重用,所以把具有独立功能的代码块组织为一个小模块,这就是函数. 函数定义和调用 定义函数 定义函数的格式如下 (1 ...

  2. python如何自定义函数_python如何自定义函数_后端开发

    c语言特点是什么_后端开发 c语言特点是:1.语言简洁.紧凑,使用方便.灵活:2.运算符丰富:3.数据结构丰富,具有现代化语言的各种数据结构:4.具有结构化的控制语句:5.语法限制不太严度格,程序设计 ...

  3. python如何定义函数_python如何定义函数

    Python 函数 函数是组织好的,可重复使用的,用来实现单一,或相关联功能的代码段. 函数能提高应用的模块性,和代码的重复利用率.你已经知道Python提供了许多内建函数,比如print().但你也 ...

  4. 详细记录python的range()函数用法

    详细记录python的range()函数用法 使用python的人都知道range()函数很方便,今天再用到他的时候发现了很多以前看到过但是忘记的细节.这里记录一下range(),复习下list的sl ...

  5. Python的零基础超详细讲解(第十二天)-Python函数及使用

    基础篇往期文章: Python的零基础超详细讲解(第一天)-Python简介以及下载_编程简单学的博客-CSDN博客 Python的零基础超详细讲解(第二天)-Python的基础语法1_编程简单学的博 ...

  6. Python之多线程:python多线程设计之同时执行多个函数命令详细攻略

    Python之多线程:python多线程设计之同时执行多个函数命令详细攻略 目录 实现功能 采取方法 应用场景 实现功能 同时执行多个函数命令 采取方法 T1.单个实现 import threadin ...

  7. python的random函数_关于random()的详细介绍

    这篇文章主要介绍了Python随机生成数模块random使用实例,本文直接给出示例代码,需要的朋友可以参考下代码如下:#!/usr/bin/env python#coding=utf-8import ...

  8. python高阶函数看不懂_Python进阶:高阶函数的详细说明

    这篇文章讲述了Python进阶:高阶函数的详细说明有需要的朋友可以参考 函数式编程 函数是Python内建支持的一种封装,我们通过把大段代码拆成函数,通过一层一层的函数调用,就可以把复杂任务分解成简单 ...

  9. python列表平均值函数_如何计算列表的平均值-统计信息和Python的均值函数详细解释

    python列表平均值函数 Mathematics and programming go hand in hand. If you are a programmer, at some point yo ...

最新文章

  1. Android代码混淆及反编译
  2. Adam是RmsProp和momentum算法的结合(列表比较)
  3. mysql 获取自增主键
  4. Find them, Catch them POJ - 1703(种类并查集)
  5. html跳转网页为什么网页无法访问,朋友的网站被网址跳转,导致官网无法正常访问...
  6. 解决 spring mvc 3.0 结合 hibernate3.2 使用tx:annotation-driven声明式事务无法提交的问题(转载)...
  7. mysql访问被拒绝1045_mysqlimport:错误:1045,访问被拒绝
  8. Android开发的内存问题
  9. 仅能帮的(非技术分享)
  10. skype显示未连接服务器,skype链接检测不到服务器
  11. 基础设置---python库--matplotlib
  12. 《软技能:代码之外的生存指南》一一35.2 找出你的短板
  13. paip.session的调试in php
  14. c51流水灯实验报告汇编语言,LED流水灯显示实验,单片机实验报告
  15. oneNote笔记名不同步
  16. 比基尼新娘沉醉花海之爱。(组图)
  17. 通过指针访问二维数组的三种方法
  18. 富途最新股权曝光:腾讯持股21% 李华有67.4%投票权
  19. 进程间通信方式有哪些-Linux进程间通信
  20. 根据epc和ra定位linux kernel panic或者应用程序的出错位置

热门文章

  1. DialogBoxIndirectParam
  2. 基于C#语言的可编程表达式计算器设计
  3. IE6 的 hover 伪类 bug
  4. 转会咯,从广州转北京咯!
  5. SIEMENS报到第一天
  6. Spring MVC浅入浅出——不吹牛逼不装逼
  7. Python第十课(函数3)
  8. 小米路由通过SSH添加静态路由表之后无法跳转的问题
  9. Windows下基于python3使用word2vec训练中文维基百科语料(三)
  10. 51nod 1243 排船的问题(二分)