pandas_openscm.grouping#
Support for grouping in various ways
Functions:
| Name | Description |
|---|---|
fix_index_name_after_groupby_quantile |
Fix the index name after performing a |
groupby_except |
Group by all index levels except specified levels |
fix_index_name_after_groupby_quantile #
fix_index_name_after_groupby_quantile(
pandas_obj: P,
new_name: str = "quantile",
copy: bool = False,
) -> P
Fix the index name after performing a groupby(...).quantile(...) operation
By default, pandas doesn't assign a name to the quantile level when doing an operation of the form given above. This fixes this, but it does assume that the quantile level is the only unnamed level in the index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pandas_obj
|
P
|
Object of which we want to fix the name |
required |
new_name
|
str
|
New name to give to the quantile column |
'quantile'
|
copy
|
bool
|
Whether to copy the object before manipulating the index name |
False
|
Returns:
| Type | Description |
|---|---|
P
|
Object, with the last level in its index renamed to |
Source code in src/pandas_openscm/grouping.py
groupby_except #
groupby_except(
pandas_obj: DataFrame | Series[Any],
non_groupers: str | list[str],
observed: bool = True,
) -> DataFrameGroupBy[Any, Any] | SeriesGroupBy[Any, Any]
Group by all index levels except specified levels
This is the inverse of pd.DataFrame.groupby.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pandas_obj
|
DataFrame | Series[Any]
|
Object to group |
required |
non_groupers
|
str | list[str]
|
Columns to exclude from the grouping |
required |
observed
|
bool
|
Whether to only return observed combinations or not |
True
|
Returns:
| Type | Description |
|---|---|
DataFrameGroupBy[Any, Any] | SeriesGroupBy[Any, Any]
|
Object, grouped by all columns except |