pandas 笔记:聚合函数agg
生活随笔
收集整理的這篇文章主要介紹了
pandas 笔记:聚合函数agg
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1 基本使用方法
DataFrame.agg(func=None, axis=0, *args, **kwargs)在指定軸上使用一項或多項操作進行聚合。
不同于numpy的聚合函數,agg只能在某一個特定的軸上執行
2 參數說明
| func | 用于聚合數據的函數 可以支持的類型有:
|
| axis |
|
| args | 傳遞給func的位置參數 |
| kargs | 傳遞給func的關鍵字參數 |
3 舉例說明
3.1 初始DataFrame
import pandas as pddata={'col1':{1:1,2:2,4:1},'col2':{1:3,2:4,4:6}} f1=pd.DataFrame(data) f1 '''col1 col2 1 1 3 2 2 4 4 1 6 '''?3.2 坐標軸
f1.agg('max') ''' col1 2 col2 6 dtype: int64 '''f1.agg('max',1) ''' 1 3 2 4 4 6 dtype: int64 '''3.3 參數列表
f1.agg(['max','mean'])'''col1 col2 max 2.000000 6.000000 mean 1.333333 4.333333 '''3.4 不同的軸不同的內容
f1.agg({'col1':'max','col2':'mean'}) ''' col1 2.000000 col2 4.333333 dtype: float64 ''' f1.agg({'col1':['max','min'],'col2':'mean'})'''col1 col2 max 2.0 NaN mean NaN 4.333333 min 1.0 NaN '''總結
以上是生活随笔為你收集整理的pandas 笔记:聚合函数agg的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: pytorch 笔记: 协同过滤user
- 下一篇: pandas 笔记:multi-inde