![python图片测量](https://img-blog.csdnimg.cn/img_convert/d6f2d60f39072e5150dd828f1d52991e.png)
python图片测量
Python-测量中心趋势 (Python - Measuring Central Tendency)
Mathematically central tendency means measuring the center or distribution of location of values of a data set. It gives an idea of the average value of the data in the data set and also an indication of how widely the values are spread in the data set. That in turn helps in evaluating the chances of a new input fitting into the existing data set and hence probability of success.
数学上的中心趋势是指测量数据集值的中心或位置分布。 它给出了数据集中数据平均值的概念,并指出了这些值在数据集中分布的范围。 反过来,这有助于评估将新输入拟合到现有数据集中的机会,从而评估成功的可能性。
There are three main measures of central tendency which can be calculated using the methods in pandas python library.
可以使用pandas python库中的方法计算出集中趋势的三种主要度量。
Mean - It is the Average value of the data which is a division of sum of the values with the number of values.
均值-它是数据的平均值,是值的总和除以值的数量。
Median - It is the middle value in distribution when the values are arranged in ascending or descending order.
中位数-当值以升序或降序排列时,它是分布中的中间值。
Mode - It is the most commonly occurring value in a distribution.
模式-它是分布中最常见的值。
计算均值和中位数 (Calculating Mean and Median)
The pandas functions can be directly used to calculate these values.
熊猫函数可以直接用于计算这些值。
import pandas as pd
#Create a Dictionary of series
d = {'Name':pd.Series(['Tom','James','Ricky','Vin','Steve','Smith','Jack',
'Lee','Chanchal','Gasper','Naviya','Andres']),
'Age':pd.Series([25,26,25,23,30,29,23,34,40,30,51,46]),
'Rating':pd.Series([4.23,3.24,3.98,2.56,3.20,4.6,3.8,3.78,2.98,4.80,4.10,3.65])}
#Create a DataFrame
df = pd.DataFrame(d)
print "Mean Values in the Distribution"
print df.mean()
print "*******************************"
print "Median Values in the Distribution"
print df.median()
Its output is as follows −
其输出如下-
Mean Values in the Distribution
Age 31.833333
Rating 3.743333
dtype: float64
*******************************
Median Values in the Distribution
Age 29.50
Rating 3.79
dtype: float64
计算模式 (Calculating Mode)
Mode may or may not be available in a distribution depending on whether the data is continous or whether there are values which has maximum frquency. We take a simple distribution below to find out the mode. Here we have a value which has maximum frequency in the distribution.
根据数据是连续的还是有最大频率的值,模式在分发中是否可用。 我们通过下面的简单分布来找出模式。 在这里,我们有一个在分布中具有最大频率的值。
import pandas as pd
#Create a Dictionary of series
d = {'Name':pd.Series(['Tom','James','Ricky','Vin','Steve','Smith','Jack',
'Lee','Chanchal','Gasper','Naviya','Andres']),
'Age':pd.Series([25,26,25,23,30,25,23,34,40,30,25,46])}
#Create a DataFrame
df = pd.DataFrame(d)
print df.mode()
Its output is as follows −
其输出如下-
![chartprop2.png](https://img-blog.csdnimg.cn/img_convert/9cc150e5ab9fa5a6f8e519007534d019.png)
Age Name
0 25.0 Andres
1 NaN Chanchal
2 NaN Gasper
3 NaN Jack
4 NaN James
5 NaN Lee
6 NaN Naviya
7 NaN Ricky
8 NaN Smith
9 NaN Steve
10 NaN Tom
11 NaN Vin
翻译自: https://www.tutorialspoint.com/python_data_science/python_measuring_central_tendency.htm
python图片测量