pandas groupby

简介: pandas.DataFrame.groupbyDataFrame.groupby(by=None, axis=0, level=None, as_index=True, sort=True, group_keys=True, squeeze=False, **kwargs)Group series...

pandas.DataFrame.groupby

DataFrame.groupby(by=None, axis=0, level=None, as_index=True, sort=True, group_keys=True, squeeze=False, **kwargs)

Group series using mapper (dict or key function, apply given function to group, return result as series) or by a series of columns.
    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()

 



目录
相关文章
|
2月前
|
数据挖掘 Python
pandas中的groupby函数应用
pandas中的groupby函数应用
16 0
pandas中的groupby函数应用
|
2月前
|
数据挖掘 数据处理 Python
Pandas中groupby后的数据排序技巧
Pandas中groupby后的数据排序技巧
110 0
|
3月前
|
索引 Python
Pandas学习笔记之Dataframe
Pandas学习笔记之Dataframe
|
3月前
|
索引 Python
Pandas学习笔记之Series
Pandas学习笔记之Series
|
3月前
|
索引 Python
【Pandas】Pandas Dataframe 常用用法
Pandas DataFrame的常用操作示例,包括筛选数据、索引操作、合并DataFrame、设置和排序索引、文本处理、列重命名、处理缺失值、排序以及删除满足特定条件的行等技巧。
58 0
|
存储 数据挖掘 索引
Pandas之Series(一)
Pandas之Series(一)
80 0
|
存储 数据挖掘 Python
为什么你需要Pandas的DataFrame
为什么你需要Pandas的DataFrame
98 0
|
索引 Python
pandas把Series组合成DataFrame
pandas把Series组合成DataFrame
|
数据可视化 数据挖掘 API
5分钟掌握Pandas GroupBy
5分钟掌握Pandas GroupBy
152 0
5分钟掌握Pandas GroupBy
|
人工智能 Shell 开发者
Pandas-dataframe|学习笔记
快速学习 Pandas-dataframe
下一篇
无影云桌面