2015-05-05 62 views
2

我试图学习所有的各种方法,我可以使用熊猫的聚合函数,但是当看着文档我真的不能告诉太多。似乎我可以传递更多参数,但我怎么知道哪些意思是什么?我如何知道熊猫的参数和关键字参数?

Aggregate Documentation

+0

这是你以后在做什么:http://pandas.pydata.org/pandas-docs /stable/groupby.html#applying-multiple-functions-at-once – EdChum

+0

这不完全是我所追求的。它展示了一些很好的例子,但并不是每个用例都是我真正追求的! – canyon289

回答

0

你是正确的,你挂不说太多的文档(对文档的贡献是非常欢迎!)。但是,如果你在一个交互式会话找一个实际GROUPBY对象的文档,这样就已经说了(相当于pd.core.groupby.DataFrameGroupBy):

In [1]: pd.core.groupby.DataFrameGroupBy.aggregate? 
Signature: pd.core.groupby.DataFrameGroupBy.aggregate(self, arg, *args, **kwargs) 
File:  c:\anaconda\lib\site-packages\pandas\core\groupby.py 
Type:  instancemethod 
Docstring: 
Aggregate using input function or dict of {column -> function} 

Parameters 
---------- 
arg : function or dict 
    Function to use for aggregating groups. If a function, must either 
    work when passed a DataFrame or when passed to DataFrame.apply. If 
    passed a dict, the keys must be DataFrame column names. 

Notes 
----- 
Numpy functions mean/median/prod/sum/std/var are special cased so the 
default behavior is applying the function along axis=0 
(e.g., np.mean(arr_2d, axis=0)) as opposed to 
mimicking the default Numpy behavior (e.g., np.mean(arr_2d)). 

Returns 
------- 
aggregated : DataFrame 

教程文档包含更多的信息,这样就可以在http://pandas.pydata.org/pandas-docs/stable/groupby.html#aggregation

被发现

你可以通过可能的参数是:

  • 的功能(如np.mean):这将适用于每列
  • 函数的列表纳秒(例如[np.mean, np.median]):每个函数将被应用到每个列
  • COL的一个字典 - > FUNC(例如{'a':np.mean, 'b':np.median}:以这种方式可以为不同的列指定不同的功能在上面所有情况下
  • ,该函数可以还通过为最常见的字符串(如'mean''median''std''first',...)来代替