omnipy.util.dataframe
Helpers for slicing multi-index pandas dataframes by label groups.
This module provides small dataframe utilities for splitting a dataframe into kept and moved row/column sections and for extracting subtables by index-level labels.
| FUNCTION | DESCRIPTION |
|---|---|
extract_subtable_by_labels |
Extract a subtable by row and column labels from selected index levels. |
select_from_labels |
Return labels from a dataframe index level that match a filter. |
split_dataframe |
Split a dataframe into kept and moved row/column sections. |
extract_subtable_by_labels
Extract a subtable by row and column labels from selected index levels.
| PARAMETER | DESCRIPTION |
|---|---|
df
|
Dataframe to slice.
|
row_labels
|
Optional row labels to keep.
DEFAULT:
|
col_labels
|
Optional column labels to keep.
DEFAULT:
|
row_level
|
Row index level used when selecting rows.
DEFAULT:
|
col_level
|
Column index level used when selecting columns.
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
|
A dataframe restricted to the requested rows and columns. |
Source code in src/omnipy/util/dataframe.py
select_from_labels
Return labels from a dataframe index level that match a filter.
| PARAMETER | DESCRIPTION |
|---|---|
df
|
Dataframe whose row or column index levels are inspected.
|
labels
|
Labels to select or exclude.
|
axis
|
|
level
|
Multi-index level to inspect.
|
invert
|
When
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
|
A tuple of matching labels from the requested index level. |
Source code in src/omnipy/util/dataframe.py
split_dataframe
Split a dataframe into kept and moved row/column sections.
| PARAMETER | DESCRIPTION |
|---|---|
df
|
Dataframe with multi-index rows and columns.
|
row_labels_to_move
|
Labels to move out of the kept row group.
|
col_labels_to_move
|
Labels to move out of the kept column group.
|
row_level
|
Row index level used for label matching.
DEFAULT:
|
col_level
|
Column index level used for label matching.
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
|
A 4-tuple containing the kept subtable, the kept-rows/moved-columns subtable, the moved-rows/kept-columns subtable, and the moved-rows/ moved-columns subtable. |