pandas.DataFrame.groupby

pandas.DataFrame.groupby() ,反悔的结果是一个Key,value的 新的Dataframe

Parameters:

by : mapping function / list of functions, dict, Series, or tuple /

list of column names. Called on each element of the object index to determine the groups. If a dict or Series is passed, the Series or dict VALUES will be used to determine the groups

axis : int, default 0

level : int, level name, or sequence of such, default None

If the axis is a MultiIndex (hierarchical), group by a particular level or levels

as_index : boolean, default True

For aggregated output, return object with group labels as the index. Only relevant for DataFrame input. as_index=False is effectively “SQL-style” grouped output

sort : boolean, default True

Sort group keys. Get better performance by turning this off. Note this does not influence the order of observations within each group. groupby preserves the order of rows within each group.

group_keys : boolean, default True

When calling apply, add group keys to index to identify pieces

squeeze : boolean, default False

reduce the dimensionality of the return type if possible, otherwise return a consistent type

Returns:

GroupBy object

Examples

DataFrame results

>>> data.groupby(func, axis=0).mean()
>>> data.groupby(['col1', 'col2'])['col3'].mean()

DataFrame with hierarchical index

>>> data.groupby(['col1', 'col2']).mean()

 

参数:

by : 映射函数/函数列表、字典、系列或元组/

列名列表。调用对象索引的每个元素来确定组。如果传递了 dict 或 Series,则 Series 或 dict VALUES 将用于确定组

:整数,默认为 0

级别:整数,级别名称或此类的序列,默认为无

如果轴是 MultiIndex(分层),则按特定级别或级别分组

as_index : 布尔值,默认为 True

对于聚合输出,返回带有组标签的对象作为索引。仅与 DataFrame 输入相关。as_index=False 是有效的“SQL 风格”分组输出

排序:布尔值,默认为真

对组键进行排序。关闭此功能可获得更好的性能。请注意,这不会影响每个组内的观察顺序。groupby 保留每个组中行的顺序。

group_keys : 布尔值,默认为 True

调用apply时,将组键添加到索引以识别碎片

挤压:布尔值,默认为假

如果可能,减少返回类型的维数,否则返回一致的类型

返回:

分组对象

posted @ 2021-12-01 16:04  faithtwo  阅读(71)  评论(0)    收藏  举报