pub struct DataFrameGroupBy<'a> { /* private fields */ }Expand description
Deferred GroupBy object for DataFrame.
Created by DataFrame::groupby(). Call aggregation methods to produce results.
Implementations§
Source§impl DataFrameGroupBy<'_>
impl DataFrameGroupBy<'_>
Sourcepub fn keys(&self) -> Vec<IndexLabel>
pub fn keys(&self) -> Vec<IndexLabel>
Group labels in group iteration order.
Sourcepub fn indices(&self) -> HashMap<IndexLabel, Vec<usize>>
pub fn indices(&self) -> HashMap<IndexLabel, Vec<usize>>
Mapping from group labels to source row positions.
Sourcepub fn groups(&self) -> HashMap<IndexLabel, Vec<usize>>
pub fn groups(&self) -> HashMap<IndexLabel, Vec<usize>>
Alias for indices, matching pandas’ groups property shape.
Sourcepub fn dtypes(&self) -> Result<Series, FrameError>
pub fn dtypes(&self) -> Result<Series, FrameError>
DTypes for grouped value columns.
Sourcepub fn plot(&self) -> Result<PlotSpec, FrameError>
pub fn plot(&self) -> Result<PlotSpec, FrameError>
Return a backend-neutral pandas-style grouped plotting request.
Sourcepub fn bar(&self) -> Result<PlotSpec, FrameError>
pub fn bar(&self) -> Result<PlotSpec, FrameError>
Return a backend-neutral pandas-style grouped bar plot request.
Sourcepub fn area(&self) -> Result<PlotSpec, FrameError>
pub fn area(&self) -> Result<PlotSpec, FrameError>
Return a backend-neutral pandas-style grouped area plot request.
Sourcepub fn scatter(&self) -> Result<PlotSpec, FrameError>
pub fn scatter(&self) -> Result<PlotSpec, FrameError>
Return a backend-neutral pandas-style grouped scatter plot request.
Sourcepub fn pie(&self) -> Result<PlotSpec, FrameError>
pub fn pie(&self) -> Result<PlotSpec, FrameError>
Return a backend-neutral pandas-style grouped pie plot request.
Sourcepub fn hist(&self) -> Result<HistogramSpec, FrameError>
pub fn hist(&self) -> Result<HistogramSpec, FrameError>
Return a backend-neutral pandas-style grouped histogram request.
Sourcepub fn boxplot(&self) -> Result<BoxPlotSpec, FrameError>
pub fn boxplot(&self) -> Result<BoxPlotSpec, FrameError>
Return a backend-neutral pandas-style grouped boxplot request.
Sourcepub fn any(&self) -> Result<DataFrame, FrameError>
pub fn any(&self) -> Result<DataFrame, FrameError>
GroupBy any (returns True if any value is truthy per group).
Sourcepub fn all(&self) -> Result<DataFrame, FrameError>
pub fn all(&self) -> Result<DataFrame, FrameError>
GroupBy all (returns True if all values are truthy per group).
Sourcepub fn sum(&self) -> Result<DataFrame, FrameError>
pub fn sum(&self) -> Result<DataFrame, FrameError>
GroupBy sum.
Sourcepub fn mean(&self) -> Result<DataFrame, FrameError>
pub fn mean(&self) -> Result<DataFrame, FrameError>
GroupBy mean.
pub fn count(&self) -> Result<DataFrame, FrameError>
Sourcepub fn min(&self) -> Result<DataFrame, FrameError>
pub fn min(&self) -> Result<DataFrame, FrameError>
GroupBy min.
Sourcepub fn max(&self) -> Result<DataFrame, FrameError>
pub fn max(&self) -> Result<DataFrame, FrameError>
GroupBy max.
Sourcepub fn std(&self) -> Result<DataFrame, FrameError>
pub fn std(&self) -> Result<DataFrame, FrameError>
GroupBy std.
Sourcepub fn var(&self) -> Result<DataFrame, FrameError>
pub fn var(&self) -> Result<DataFrame, FrameError>
GroupBy var.
Sourcepub fn median(&self) -> Result<DataFrame, FrameError>
pub fn median(&self) -> Result<DataFrame, FrameError>
GroupBy median.
pub fn idxmin(&self) -> Result<DataFrame, FrameError>
Sourcepub fn idxmax(&self) -> Result<DataFrame, FrameError>
pub fn idxmax(&self) -> Result<DataFrame, FrameError>
GroupBy idxmax. Returns the index label of the maximum value for each group.
pub fn first(&self) -> Result<DataFrame, FrameError>
Sourcepub fn last(&self) -> Result<DataFrame, FrameError>
pub fn last(&self) -> Result<DataFrame, FrameError>
GroupBy last.
pub fn nunique(&self) -> Result<DataFrame, FrameError>
Sourcepub fn prod(&self) -> Result<DataFrame, FrameError>
pub fn prod(&self) -> Result<DataFrame, FrameError>
GroupBy prod (product of non-null values per group).
Sourcepub fn agg(
&self,
func_map: &HashMap<String, String>,
) -> Result<DataFrame, FrameError>
pub fn agg( &self, func_map: &HashMap<String, String>, ) -> Result<DataFrame, FrameError>
Aggregate with per-column function mapping.
Matches df.groupby(col).agg({'B': 'sum', 'C': 'mean'}) semantics.
func_map: mapping of column_name → aggregation function name.
Only the specified columns are included in the output.
Sourcepub fn aggregate(
&self,
func_map: &HashMap<String, String>,
) -> Result<DataFrame, FrameError>
pub fn aggregate( &self, func_map: &HashMap<String, String>, ) -> Result<DataFrame, FrameError>
pandas spelling alias for Self::agg.
Sourcepub fn agg_list(&self, funcs: &[&str]) -> Result<DataFrame, FrameError>
pub fn agg_list(&self, funcs: &[&str]) -> Result<DataFrame, FrameError>
Aggregate with multiple functions applied to all value columns.
Matches df.groupby(col).agg(['sum', 'mean']) semantics.
Returns a DataFrame where each original value column is expanded into
N columns (one per function), named {col}_{func}.
Sourcepub fn agg_dict_list(
&self,
func_map: &HashMap<String, Vec<String>>,
) -> Result<DataFrame, FrameError>
pub fn agg_dict_list( &self, func_map: &HashMap<String, Vec<String>>, ) -> Result<DataFrame, FrameError>
Aggregate with a per-column list of functions.
Matches df.groupby(col).agg({'a': ['sum', 'mean'], 'b': ['min']})
semantics. For each entry in func_map, every function is applied to
the named input column, producing one output column per (input_col,
func) pair named {col}_{func}. Output column order follows the
original DataFrame’s column order; funcs within a column follow the
slice order supplied. Columns not in func_map are excluded, group-by
key columns are rejected, and an empty func list is rejected.
Sourcepub fn agg_named(
&self,
specs: &[(&str, &str, &str)],
) -> Result<DataFrame, FrameError>
pub fn agg_named( &self, specs: &[(&str, &str, &str)], ) -> Result<DataFrame, FrameError>
Named aggregation: each tuple is (output_name, input_column, function).
Matches df.groupby('g').agg(out=('col', 'func')) in pandas.
The output DataFrame has columns named by output_name, computed
by applying function to input_column within each group.
Example:
let result = df.groupby(&["region"]).unwrap().agg_named(&[
("total_sales", "revenue", "sum"),
("avg_price", "price", "mean"),
("num_orders", "order_id", "count"),
]).unwrap();Sourcepub fn agg_multi(
&self,
func_map: &HashMap<String, Vec<String>>,
) -> Result<DataFrame, FrameError>
pub fn agg_multi( &self, func_map: &HashMap<String, Vec<String>>, ) -> Result<DataFrame, FrameError>
Aggregate with multiple functions per column.
Matches df.groupby(col).agg({'A': ['sum', 'mean'], 'B': ['count']}).
Output columns are named {col}_{func}.
Sourcepub fn apply<F>(&self, func: F) -> Result<DataFrame, FrameError>
pub fn apply<F>(&self, func: F) -> Result<DataFrame, FrameError>
Apply a custom function to each group DataFrame.
Matches pandas 2.x df.groupby(col).apply(func, include_groups=False)
for DataFrame-returning functions. Results are concatenated vertically;
multi-row group results receive group-key row MultiIndex metadata.
Sourcepub fn apply_with_include_groups<F>(
&self,
include_groups: bool,
func: F,
) -> Result<DataFrame, FrameError>
pub fn apply_with_include_groups<F>( &self, include_groups: bool, func: F, ) -> Result<DataFrame, FrameError>
Apply a DataFrame-returning function with explicit include_groups.
Sourcepub fn apply_scalar<F>(&self, name: &str, func: F) -> Result<Series, FrameError>
pub fn apply_scalar<F>(&self, name: &str, func: F) -> Result<Series, FrameError>
Apply a scalar-returning function to each group.
Rust’s static return types expose pandas’ scalar-returning
GroupBy.apply shape as an explicit API: one Series value per group,
indexed by the group keys.
Sourcepub fn apply_scalar_with_include_groups<F>(
&self,
name: &str,
include_groups: bool,
func: F,
) -> Result<Series, FrameError>
pub fn apply_scalar_with_include_groups<F>( &self, name: &str, include_groups: bool, func: F, ) -> Result<Series, FrameError>
Apply a scalar-returning function with explicit include_groups.
Sourcepub fn apply_series<F>(&self, func: F) -> Result<DataFrame, FrameError>
pub fn apply_series<F>(&self, func: F) -> Result<DataFrame, FrameError>
Apply a Series-returning function to each group.
Returned Series indexes become output columns. The column union is first-seen ordered and groups missing a Series label receive NaN, which matches pandas’ sparse DataFrame shape for uneven Series returns.
Sourcepub fn apply_series_with_include_groups<F>(
&self,
include_groups: bool,
func: F,
) -> Result<DataFrame, FrameError>
pub fn apply_series_with_include_groups<F>( &self, include_groups: bool, func: F, ) -> Result<DataFrame, FrameError>
Apply a Series-returning function with explicit include_groups.
Sourcepub fn apply_series_stacked<F>(
&self,
name: &str,
func: F,
) -> Result<DataFrame, FrameError>
pub fn apply_series_stacked<F>( &self, name: &str, func: F, ) -> Result<DataFrame, FrameError>
Apply a Series-returning function and stack each returned Series row.
This is the Rust API for pandas’ GroupBy.apply path where returned
Series objects do not share identical labels. The result is represented
as a one-column DataFrame because Series does not yet carry row
MultiIndex metadata; group keys and returned Series labels are retained
on the DataFrame row MultiIndex.
Sourcepub fn apply_series_stacked_with_include_groups<F>(
&self,
name: &str,
include_groups: bool,
func: F,
) -> Result<DataFrame, FrameError>
pub fn apply_series_stacked_with_include_groups<F>( &self, name: &str, include_groups: bool, func: F, ) -> Result<DataFrame, FrameError>
Apply a stacked Series-returning function with explicit include_groups.
pub fn transform(&self, func_name: &str) -> Result<DataFrame, FrameError>
Sourcepub fn transform_list(&self, funcs: &[&str]) -> Result<DataFrame, FrameError>
pub fn transform_list(&self, funcs: &[&str]) -> Result<DataFrame, FrameError>
Transform each group with multiple named aggregation functions.
Matches df.groupby(col).transform(['sum', 'mean']) for the
supported function set. One output column is produced per
{input_column}_{func} pair, and each aggregated value is
broadcast back to the original row positions of its group.
Sourcepub fn transform_fn<F>(&self, func: F) -> Result<DataFrame, FrameError>
pub fn transform_fn<F>(&self, func: F) -> Result<DataFrame, FrameError>
Transform each group using a user-supplied closure.
Matches df.groupby(col).transform(lambda s: ...) — the closure
receives a per-group Series (one call per value column × per group)
and must return a Series of the same length. Values are scattered
back to their original row positions, so the output DataFrame has the
same shape and index as the input. Group-by key columns are excluded
from the transform (matching pandas). The closure returning a Series
whose length differs from its input is rejected.
Sourcepub fn size(&self) -> Result<Series, FrameError>
pub fn size(&self) -> Result<Series, FrameError>
GroupBy size (number of rows per group).
Sourcepub fn filter<F>(&self, func: F) -> Result<DataFrame, FrameError>
pub fn filter<F>(&self, func: F) -> Result<DataFrame, FrameError>
Filter groups using a function that returns bool for each group.
Analogous to df.groupby(col).filter(func).
The function receives a sub-DataFrame for each group and should return
true to keep the group or false to drop it. Returns a DataFrame
containing only the rows belonging to kept groups, preserving original
index and column order.
Sourcepub fn cumsum(&self) -> Result<DataFrame, FrameError>
pub fn cumsum(&self) -> Result<DataFrame, FrameError>
GroupBy cumulative sum.
Matches df.groupby(col).cumsum().
Sourcepub fn cumprod(&self) -> Result<DataFrame, FrameError>
pub fn cumprod(&self) -> Result<DataFrame, FrameError>
GroupBy cumulative product.
Matches df.groupby(col).cumprod().
Sourcepub fn cummax(&self) -> Result<DataFrame, FrameError>
pub fn cummax(&self) -> Result<DataFrame, FrameError>
GroupBy cumulative max.
Matches df.groupby(col).cummax().
Sourcepub fn cummin(&self) -> Result<DataFrame, FrameError>
pub fn cummin(&self) -> Result<DataFrame, FrameError>
GroupBy cumulative min.
Matches df.groupby(col).cummin().
Sourcepub fn rank(
&self,
method: &str,
ascending: bool,
na_option: &str,
) -> Result<DataFrame, FrameError>
pub fn rank( &self, method: &str, ascending: bool, na_option: &str, ) -> Result<DataFrame, FrameError>
GroupBy rank within each group.
Matches df.groupby(col).rank().
method: “average” (default), “min”, “max”, “first”, “dense”
ascending: rank direction (default true = smallest gets rank 1)
na_option: “keep” (NaN stays NaN), “top” (NaN gets lowest ranks), “bottom” (NaN gets highest ranks)
Sourcepub fn rank_with_pct(
&self,
method: &str,
ascending: bool,
na_option: &str,
pct: bool,
) -> Result<DataFrame, FrameError>
pub fn rank_with_pct( &self, method: &str, ascending: bool, na_option: &str, pct: bool, ) -> Result<DataFrame, FrameError>
GroupBy rank within each group and optionally scale the ranks to percentiles.
Sourcepub fn shift(&self, periods: i64) -> Result<DataFrame, FrameError>
pub fn shift(&self, periods: i64) -> Result<DataFrame, FrameError>
GroupBy shift within each group.
Matches df.groupby(col).shift(periods).
Sourcepub fn diff(&self, periods: usize) -> Result<DataFrame, FrameError>
pub fn diff(&self, periods: usize) -> Result<DataFrame, FrameError>
GroupBy diff within each group.
Matches df.groupby(col).diff(periods).
Sourcepub fn nth(&self, n: i64) -> Result<DataFrame, FrameError>
pub fn nth(&self, n: i64) -> Result<DataFrame, FrameError>
GroupBy nth: select the nth row from each group.
Matches df.groupby(col).nth(n). Returns a DataFrame with one row per group.
Negative n counts from the end.
Sourcepub fn head(&self, n: i64) -> Result<DataFrame, FrameError>
pub fn head(&self, n: i64) -> Result<DataFrame, FrameError>
GroupBy head: select first n rows per group.
Matches df.groupby(col).head(n), including pandas’ negative n:
head(-k) keeps all but the last k rows of each group. Verified vs
live pandas 2.2.3.
Sourcepub fn tail(&self, n: i64) -> Result<DataFrame, FrameError>
pub fn tail(&self, n: i64) -> Result<DataFrame, FrameError>
GroupBy tail: select last n rows per group.
Matches df.groupby(col).tail(n), including pandas’ negative n:
tail(-k) drops the first k rows of each group. Verified vs live
pandas 2.2.3.
Sourcepub fn take(&self, indices: &[i64]) -> Result<DataFrame, FrameError>
pub fn take(&self, indices: &[i64]) -> Result<DataFrame, FrameError>
Return positional rows from each group.
Matches pd.DataFrameGroupBy.take(indices), resolving negative
positions relative to each group’s length.
Sourcepub fn sample(
&self,
n: Option<usize>,
frac: Option<f64>,
replace: bool,
seed: Option<u64>,
) -> Result<DataFrame, FrameError>
pub fn sample( &self, n: Option<usize>, frac: Option<f64>, replace: bool, seed: Option<u64>, ) -> Result<DataFrame, FrameError>
Randomly sample rows from each group.
Matches pd.DataFrameGroupBy.sample(n=..., frac=..., replace=...).
Sourcepub fn pct_change(&self, periods: i64) -> Result<DataFrame, FrameError>
pub fn pct_change(&self, periods: i64) -> Result<DataFrame, FrameError>
GroupBy pct_change within each group.
Matches df.groupby(col).pct_change().
Sourcepub fn value_counts(&self) -> Result<DataFrame, FrameError>
pub fn value_counts(&self) -> Result<DataFrame, FrameError>
GroupBy value_counts: count of each unique value per group.
Matches df.groupby(col)[value_col].value_counts().
Returns a DataFrame with group key + value as index and counts as values.
Sourcepub fn describe(&self) -> Result<DataFrame, FrameError>
pub fn describe(&self) -> Result<DataFrame, FrameError>
GroupBy describe: summary statistics per group.
Matches df.groupby(col).describe(). Returns count, mean, std, min,
25%/50%/75% quantiles, and max for each group’s numeric columns.
Sourcepub fn get_group(&self, name: &str) -> Result<DataFrame, FrameError>
pub fn get_group(&self, name: &str) -> Result<DataFrame, FrameError>
Retrieve a single group as a DataFrame.
Matches groupby.get_group(name). The name should match the
debug representation of the group key value (e.g. "a" for Utf8
or "Int64(1)" for numeric keys).
Sourcepub fn cumcount(&self) -> Result<Series, FrameError>
pub fn cumcount(&self) -> Result<Series, FrameError>
Assign within-group cumulative count (0-based).
Matches groupby.cumcount(). Returns a Series of Int64 with a
monotonically increasing counter within each group.
Sourcepub fn cumcount_with_ascending(
&self,
ascending: bool,
) -> Result<Series, FrameError>
pub fn cumcount_with_ascending( &self, ascending: bool, ) -> Result<Series, FrameError>
Assign within-group cumulative count (0-based) with explicit direction.
Matches groupby.cumcount(ascending=...).
Sourcepub fn ngroup(&self) -> Result<Series, FrameError>
pub fn ngroup(&self) -> Result<Series, FrameError>
Assign group number to each row.
Matches groupby.ngroup(). Returns a Series of Int64 where
each row gets the ordinal number of its group.
pub fn ngroup_with_ascending( &self, ascending: bool, ) -> Result<Series, FrameError>
Sourcepub fn pipe<F>(&self, func: F) -> Result<DataFrame, FrameError>
pub fn pipe<F>(&self, func: F) -> Result<DataFrame, FrameError>
Pipe the GroupBy through a function.
Matches groupby.pipe(func).
Sourcepub fn corr(&self) -> Result<DataFrame, FrameError>
pub fn corr(&self) -> Result<DataFrame, FrameError>
Pairwise Pearson correlation matrix per group.
Matches pd.DataFrameGroupBy.corr() by stacking each group’s
DataFrame correlation matrix under group-key row metadata.
Sourcepub fn cov(&self) -> Result<DataFrame, FrameError>
pub fn cov(&self) -> Result<DataFrame, FrameError>
Pairwise covariance matrix per group.
Matches pd.DataFrameGroupBy.cov() by stacking each group’s
DataFrame covariance matrix under group-key row metadata.
Sourcepub fn corrwith(&self, other: &DataFrame) -> Result<DataFrame, FrameError>
pub fn corrwith(&self, other: &DataFrame) -> Result<DataFrame, FrameError>
Column-wise correlation against another DataFrame per group.
Matches the DataFrameGroupBy.corrwith(other) result shape: one row
per group and one column per shared numeric column.
pub fn sem(&self) -> Result<DataFrame, FrameError>
Sourcepub fn skew(&self) -> Result<DataFrame, FrameError>
pub fn skew(&self) -> Result<DataFrame, FrameError>
Skewness per group (Fisher’s definition, bias=False).
Matches groupby.skew().
Sourcepub fn kurtosis(&self) -> Result<DataFrame, FrameError>
pub fn kurtosis(&self) -> Result<DataFrame, FrameError>
Kurtosis per group (Fisher’s excess, bias=False).
Matches groupby.kurtosis().
Sourcepub fn kurt(&self) -> Result<DataFrame, FrameError>
pub fn kurt(&self) -> Result<DataFrame, FrameError>
Alias for kurtosis() — pandas exposes both df.groupby(by).kurt()
and .kurtosis(). Parity requires both spellings.
Sourcepub fn ohlc(&self) -> Result<DataFrame, FrameError>
pub fn ohlc(&self) -> Result<DataFrame, FrameError>
Open-High-Low-Close per group.
Matches the current FrankenPandas groupby.ohlc() data contract.
The returned DataFrame keeps its flat storage column names while
carrying the pandas-style column MultiIndex in sidecar metadata.
Sourcepub fn ohlc_column_multiindex(&self) -> Result<MultiIndex, FrameError>
pub fn ohlc_column_multiindex(&self) -> Result<MultiIndex, FrameError>
pandas-style column MultiIndex for groupby.ohlc().
The first level is the source value column and the second level is one
of open, high, low, or close.
Sourcepub fn ohlc_with_column_multiindex(
&self,
) -> Result<(DataFrame, MultiIndex), FrameError>
pub fn ohlc_with_column_multiindex( &self, ) -> Result<(DataFrame, MultiIndex), FrameError>
Return the current flat OHLC frame plus pandas-style MultiIndex columns.
pub fn ffill(&self, limit: Option<usize>) -> Result<DataFrame, FrameError>
Sourcepub fn bfill(&self, limit: Option<usize>) -> Result<DataFrame, FrameError>
pub fn bfill(&self, limit: Option<usize>) -> Result<DataFrame, FrameError>
Backward-fill missing values within each group.
Matches pd.GroupBy.bfill(). Within each group, fills NaN values
with the next non-NaN value.
Sourcepub fn fillna(&self, value: &Scalar) -> Result<DataFrame, FrameError>
pub fn fillna(&self, value: &Scalar) -> Result<DataFrame, FrameError>
Fill missing values within each group using a scalar.
Matches pd.GroupBy.fillna(value).
Sourcepub fn expanding(&self, min_periods: Option<usize>) -> GroupByExpanding<'_>
pub fn expanding(&self, min_periods: Option<usize>) -> GroupByExpanding<'_>
Grouped expanding window operations.
Matches pd.DataFrameGroupBy.expanding(min_periods=...).
Sourcepub fn ewm(&self, span: Option<f64>, alpha: Option<f64>) -> GroupByEwm<'_>
pub fn ewm(&self, span: Option<f64>, alpha: Option<f64>) -> GroupByEwm<'_>
Grouped exponentially weighted moving window operations.
Matches pd.DataFrameGroupBy.ewm(span=..., alpha=...).
Sourcepub fn rolling(&self, window: usize) -> GroupByRolling<'_>
pub fn rolling(&self, window: usize) -> GroupByRolling<'_>
Grouped rolling window operations.
Matches pd.DataFrameGroupBy.rolling(window). Returns a
GroupByRolling struct that applies rolling operations per group.
Sourcepub fn resample(&self, freq: &str) -> GroupByResample<'_>
pub fn resample(&self, freq: &str) -> GroupByResample<'_>
Grouped resampling.
Matches pd.DataFrameGroupBy.resample(freq). Returns a
GroupByResample struct that applies resampling per group.