DataFrame.rheon.unnest

DataFrameRheonNamespace.unnest(specs: Iterable[dict[str, Any]] | ModelBank | str | PathLike[str], *, separator: str | None = None) → DataFrame[source]

Turn each spec’s output column in a frame into one column per field.

It is LazyFrameRheonNamespace.unnest() for a frame in memory, run at once.

Parameters

specs, separator

As LazyFrameRheonNamespace.unnest() takes them: the specs whose output columns to unnest, and a text to name each column after its spec too, as {spec}{separator}{name}, as Polars 2.0’s DataFrame.unnest(separator=) names a struct’s fields.

Returns

The frame with each output column replaced by its fields: each scalar field under its own name, and each coef list as one named column per coefficient, as LazyFrameRheonNamespace.unnest() lists them.

Raises

What LazyFrameRheonNamespace.unnest() raises, on the call.

Examples

This code reads df from Example data:

spec = rp.spec.ewridge("ridge", targets=["y"], features=["x0", "x1"], half_life=100.0)
flat = df.rheon.fit_predict([spec]).rheon.unnest([spec])
print(flat.select("^coef_.*$").columns)
['coef_y_intercept', 'coef_y_x0', 'coef_y_x1']

See also