新聞中心
在Python的數(shù)據(jù)分析庫pandas中,mean(平均值)、std(標(biāo)準(zhǔn)差)和skew(偏度)是常用的統(tǒng)計量,這些統(tǒng)計量可以幫助我們更好地理解數(shù)據(jù)的特性和分布情況。

創(chuàng)新互聯(lián)是一家專業(yè)提供鎮(zhèn)雄企業(yè)網(wǎng)站建設(shè),專注與成都網(wǎng)站設(shè)計、網(wǎng)站建設(shè)、H5高端網(wǎng)站建設(shè)、小程序制作等業(yè)務(wù)。10年已為鎮(zhèn)雄眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)站制作公司優(yōu)惠進(jìn)行中。
1、mean(平均值):mean函數(shù)用于計算數(shù)據(jù)集的平均值,它返回的是數(shù)據(jù)集所有元素的平均值,如果數(shù)據(jù)集為空,mean函數(shù)將返回NaN。
我們有一個包含數(shù)字1, 2, 3, 4, 5的數(shù)據(jù)集:
import pandas as pd data = [1, 2, 3, 4, 5] df = pd.DataFrame(data, columns=['numbers']) print(df)
輸出:
numbers 0 1 1 2 2 3 3 4 4 5
我們可以使用mean函數(shù)來計算這個數(shù)據(jù)集的平均值:
print(df['numbers'].mean())
輸出:
3、0
2、std(標(biāo)準(zhǔn)差):std函數(shù)用于計算數(shù)據(jù)集的標(biāo)準(zhǔn)差,標(biāo)準(zhǔn)差是衡量數(shù)據(jù)集中數(shù)值偏離其平均值的程度,標(biāo)準(zhǔn)差越大,說明數(shù)據(jù)的離散程度越大;標(biāo)準(zhǔn)差越小,說明數(shù)據(jù)的離散程度越小,如果數(shù)據(jù)集為空,std函數(shù)將返回NaN。
我們有一個包含數(shù)字1, 2, 3, 4, 5的數(shù)據(jù)集:
import pandas as pd data = [1, 2, 3, 4, 5] df = pd.DataFrame(data, columns=['numbers']) print(df)
我們可以使用std函數(shù)來計算這個數(shù)據(jù)集的標(biāo)準(zhǔn)差:
print(df['numbers'].std())
輸出:
1、4142135623730951
3、skew(偏度):skew函數(shù)用于計算數(shù)據(jù)集的偏度,偏度是衡量數(shù)據(jù)分布的不對稱性,正偏度表示數(shù)據(jù)右偏,即數(shù)據(jù)分布的尾部在右側(cè);負(fù)偏度表示數(shù)據(jù)左偏,即數(shù)據(jù)分布的尾部在左側(cè),如果數(shù)據(jù)集為空,skew函數(shù)將返回NaN。
我們有一個包含數(shù)字1, 2, 3, 4, 5的數(shù)據(jù)集:
import pandas as pd from scipy.stats import skew import numpy as np data = [1, 2, 3, 4, 5] df = pd.DataFrame(data, columns=['numbers']) print(df)
我們可以使用skew函數(shù)來計算這個數(shù)據(jù)集的偏度:
print(skew(df['numbers']))
輸出:
0、0000000000000000
這是因為我們的數(shù)據(jù)集是一個完全對稱的數(shù)據(jù)集,所以偏度為0,如果我們改變數(shù)據(jù)集,例如添加一些大于5的數(shù)字,我們可以看到偏度的變化。
data = [1, 2, 3, 4, 5, 6, 7, 8, 9] df = pd.DataFrame(data, columns=['numbers']) print(df) print(skew(df['numbers']))
輸出:
numbers
0 1.000000e+00
1 2.000000e+00
2 3.000000e+00
3 4.000000e+00
4 5.000000e+00
5 6.000000e+01
6 7.000000e+01
7 8.000000e+
文章名稱:pandasmean,std,skew
標(biāo)題來源:http://www.dlmjj.cn/article/cdhchdd.html


咨詢
建站咨詢
