本文共 2774 字,大约阅读时间需要 9 分钟。
Group DataFrame using a mapper or by a Series of columns.
A groupby operation involves some combination of splitting the object, applying a function, and combining the results. This can be used to group large amounts of data and compute operations on these groups.
by : mapping, function, label, or list of labes
Used to determine the groups for the groupby.
If by is a function
, it’s called on each value of the object’s index.
If a dict
or Series
is passed, the Series or dict VALUES will be used to determine the groups.
If an ndarray
is passed, the values are used as-is determine the groups.
A label or list of labels may be passed to group by the columns in self.
axis : {0 or ‘index’, 1 or ‘columns’}, default 0
Split along rows (0) or columns (1).
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 : bool, default True
For aggregated output, return object with group labels. Only relevant for DataFrame input. as_index=False is effectively ‘SQL-style’ grouped output.
sort : bool, 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 : bool, default True
When calling apply, add group keys to index to identify pieces.
squeeze : bool, default True
Reduce the dimensionality of the return type if possible, otherwise return a consistent type.
observed : bool, default False
This only applies if any of the groupers are Categoricals.
If True : only show observed values for categorical groupers.
If False : show all values for categorical groupers.
dropna : bool, default True
If True, and if group keys contain NA values, NA values together with row/column will be dropped.
If False, NA values will also be treated as the key in groups.
Returns a groupby object that contains information about the groups.
DataFrame.rank(axis=0, method='average', numeric_only=None, na_option='keep', ascending=True,pct=False)
Computing numerical data ranks (1 through n) along axis.
By default, equal values are assigned a rank that is the average of the ranks of those values.
method : {‘average’, ‘min’, ‘max’, ‘first’, ‘dense’}, default ‘average’
How to rank the group of records that have the same value.
method是针对rank排名讲的,指的是原始数据序列中存在相同的数据,这些相同数据返回的rank排名,如果是max就取相同数据所占顺序中最大的,min就是其中最小的。first就是按照他们在原始数据中所出现的顺序给定rank。
转载地址:http://zdge.baihongyu.com/