我正在尝试学习各种方法,我可以在Pandas中使用聚合函数,但在查看文档时,我真的无法说清楚。好像我可以传递更多参数,但我怎么知道哪些是什么意思呢?
答案 0 :(得分: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]
):每个功能都将应用于每一列{'a':np.mean, 'b':np.median}
:通过这种方式,您可以为不同的列指定不同的函数'mean'
,'median'
,'std'
'first'
,... )