dict_to_panel¶
yohou.utils.panel.dict_to_panel(data)
¶
Convert a dict of group DataFrames to a single DataFrame with prefixed columns.
Takes a dictionary mapping group names to DataFrames and combines them into
a single DataFrame where each group's columns are prefixed with the group name
using the __ separator pattern (
Parameters¶
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict of str to pl.DataFrame or pl.DataFrame
|
Either a dictionary mapping group names to DataFrames, or an already combined DataFrame. Each DataFrame in the dict must have a "time" column and additional feature columns. |
required |
Returns¶
| Type | Description |
|---|---|
DataFrame or None
|
Combined DataFrame with prefixed columns. The "time" column is shared
across all groups. Other columns are prefixed as |
Examples¶
>>> import polars as pl
>>> # Dictionary of group DataFrames
>>> data_dict = {
... "sales": pl.DataFrame({
... "time": [1, 2, 3],
... "store_1": [100, 110, 120],
... "store_2": [150, 160, 170],
... }),
... "inventory": pl.DataFrame({
... "time": [1, 2, 3],
... "warehouse_1": [50, 55, 60],
... "warehouse_2": [75, 80, 85],
... }),
... }
>>> df_panel = dict_to_panel(data_dict)
>>> sorted(df_panel.columns)
['inventory__warehouse_1', 'inventory__warehouse_2', 'sales__store_1', 'sales__store_2', 'time']
>>> # Already a DataFrame - returns unchanged
>>> df_existing = pl.DataFrame({"time": [1, 2, 3], "sales__store_1": [100, 110, 120]})
>>> result = dict_to_panel(df_existing)
>>> result.equals(df_existing)
True
See Also¶
inspect_panel: Inspect DataFrame to identify global and local columnsget_group_df: Extract a single panel group from a combined DataFrame
Notes¶
This function is the inverse operation of extracting groups with get_group_df. It's commonly used internally by forecasters to convert between the dict representation (easier for per-group processing) and the prefixed column representation (polars-native format).
Source Code¶
Show/Hide source
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 | |
Tutorials¶
The following example notebooks use this component:
-
How to Preprocess Panel Data
Panel-Data
Automatic panel-aware transformation (StandardScaler, rolling stats, imputation) plus manual per-group workflows with get_group_df and dict_to_panel.