- Python 資料科學教程
- Python 資料科學 - 首頁
- Python 資料科學 - 入門
- Python 資料科學 - 環境設定
- Python 資料科學 - Pandas
- Python 資料科學 - Numpy
- Python 資料科學 - SciPy
- Python 資料科學 - Matplotlib
- Python 資料處理
- Python 資料操作
- Python 資料清洗
- Python 處理 CSV 資料
- Python 處理 JSON 資料
- Python 處理 XLS 資料
- Python 關係資料庫
- Python NoSQL 資料庫
- Python 日期和時間
- Python 資料整理
- Python 資料聚合
- Python 讀取 HTML 頁面
- Python 處理非結構化資料
- Python 詞語標記化
- Python 詞幹提取和詞形還原
- Python 資料視覺化
- Python 圖表屬性
- Python 圖表樣式
- Python 箱線圖
- Python 熱力圖
- Python 散點圖
- Python 氣泡圖
- Python 3D 圖表
- Python 時間序列
- Python 地理資料
- Python 圖資料
Python - 方差測量
在統計學中,方差是衡量資料集中的一個值與平均值之間差異程度的指標。換句話說,它表示值的分散程度。它是透過使用標準差來衡量的。另一種常用的方法是偏度。
這兩種方法都是透過使用 pandas 庫中提供的函式來計算的。
測量標準差
標準差是方差的平方根。方差是資料集中的值與平均值之差的平方的平均值。在 Python 中,我們使用 pandas 庫中的 std() 函式計算此值。
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]),
'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)
# Calculate the standard deviation
print df.std()
其輸出如下所示 -
Age 7.265527 Rating 0.661628 dtype: float64
測量偏度
它用於確定資料是對稱的還是偏斜的。如果指數在 -1 到 1 之間,則分佈是對稱的。如果指數不超過 -1,則它向左偏斜;如果它至少為 1,則它向右偏斜。
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]),
'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 df.skew()
其輸出如下所示 -
Age 1.443490 Rating -0.153629 dtype: float64
因此,年齡評級的分佈是對稱的,而年齡的分佈則向右偏斜。
廣告