申明:本系列文章是自己在學習《利用Python進行數據分析》這本書的過程中,為了方便后期自己鞏固知識而整理。
In [1]: import numpy as np In [2]: import pandas as pd In [3]: from pandas import DataFrame,Series In [4]: data = {'class':['語文','數學','英語'],'score':[120,130,140]} In [5]: frame = DataFrame(data) In [6]: frame Out[6]: class score 0 語文 120 1 數學 130 2 英語 140
我們來匯總一下成績:
首先,我們通過字典標記的方式,可以將DataFrame的列轉成一個Series:
In [18]: frame.score Out[18]: 0 120 1 130 2 140 Name: score, dtype: int64
然后,我們再進行匯總統計:
In [20]: frame.sum() Out[20]: class 語文數學英語 score 390 dtype: object
當然,還有別的統計法則:
idxmin 最小值的索引值
idxmax 最大值的索引值
describe 一次性 多種維度統計
count 非NA值的數量
min 最小值
max 最大值
argmin 最小值的索引位置
argmax 最大值的索引位置
sum 總和
mean 平均數
median 算術中位數
mad 根據平均值計算平均絕對離差
var 樣本值的方差
std 樣本值的標准差
skew 樣本值的偏度(三階矩陣)
kurt 樣本值的峰度(四階矩陣)
cumsum 樣本值的累積和
cummin、cummax 樣本值的最大值、最小值
cumprod 樣本值的累計積
diff 計算一階差分
pct_change 計算百分數變化