get_group_df¶
yohou.utils.panel.get_group_df(df, group_name, schema, key_cols=('time',))
¶
Extract and rename columns for a specific panel group.
Selects columns matching the group prefix pattern (
Parameters¶
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame with panel data columns.
Must contain columns listed in |
required |
group_name
|
str
|
Group prefix to extract (e.g., "sales", "inventory").
Columns matching |
required |
schema
|
dict of str to pl.DataType
|
Schema mapping unprefixed column names to their data types. Used to determine which columns to extract. Can contain both local columns (will have group prefix in df) and global columns (no prefix in df). Example: {"store_1": pl.Int64, "store_2": pl.Int64, "holiday": pl.Boolean} |
required |
key_cols
|
tuple of str
|
Index columns to preserve in the output (e.g. |
("time",)
|
Returns¶
| Type | Description |
|---|---|
DataFrame
|
DataFrame with "time" column and unprefixed group columns.
Local columns are renamed from |
Examples¶
>>> import polars as pl
>>> df = pl.DataFrame({
... "time": [1, 2, 3],
... "sales__store_1": [100, 110, 120],
... "sales__store_2": [150, 160, 170],
... "holiday": [True, False, True], # Global column
... "inventory__store_1": [50, 55, 60],
... })
>>> # Schema includes both local and global columns
>>> schema = {"store_1": pl.Int64, "store_2": pl.Int64, "holiday": pl.Boolean}
>>> df_sales = get_group_df(df, "sales", schema)
>>> df_sales.columns
['time', 'store_1', 'store_2', 'holiday']
>>> df_sales.shape
(3, 4)
See Also¶
inspect_panel: Inspect DataFrame to identify global and local columnsselect_panel_columns: Filter DataFrame to panel group columns and global columns
Notes¶
This function is used internally by forecasters to extract individual panel groups for processing, particularly in the context of the new architecture where schemas store unprefixed column names.
For X (feature) data, the schema typically combines local_X_actual_schema_ and shared_X_actual_schema_, allowing each group to access both its own features and shared features.
Source Code¶
Show/Hide source
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | |