Skip to content

unnest

Unnest(features)

Bases: Transform

Decompose struct columns into separate columns for each field.

Example:

data_frame = pl.Series(
    "c",
    [
        {"a": 1, "t": 1},
        {"a": 4, "t": 2},
        {"a": 7, "t": 3},
        {"a": 10, "t": 4},
        {"a": 15, "t": 5},
    ],
).to_frame()
The transformed_data will be:
pl.DataFrame(
    {
        "a": [1, 4, 7, 10, 15],
        "t": [1, 2, 3, 4, 5],
    },
)
.

Initializes the Unnest transform.

Parameters:

Name Type Description Default
features ColumnNameOrSelector | Collection[ColumnNameOrSelector]

The features to unnest. Treats the selection as a parameter to polars unnest method. You can use regular expressions by wrapping the argument by ^ and $.

required
Source code in src/flowcean/polars/transforms/unnest.py
41
42
43
44
45
46
47
48
49
50
51
52
def __init__(
    self,
    features: ColumnNameOrSelector | Collection[ColumnNameOrSelector],
) -> None:
    """Initializes the Unnest transform.

    Args:
        features: The features to unnest. Treats the selection as a
            parameter to polars `unnest` method. You can use regular
            expressions by wrapping the argument by ^ and $.
    """
    self.features = features