polars.Expr.reshape#

Expr.reshape(dims: tuple[int, ...]) Expr[source]#

Reshape this Expr to a flat Series or a Series of Lists.

Parameters:
dims

Tuple of the dimension sizes. If a -1 is used in any of the dimensions, that dimension is inferred.

Returns:
Expr

If a single dimension is given, results in a flat Series of shape (len,). If a multiple dimensions are given, results in a Series of Lists with shape (rows, cols).

Examples

>>> df = pl.DataFrame({"foo": [1, 2, 3, 4, 5, 6, 7, 8, 9]})
>>> df.select(pl.col("foo").reshape((3, 3)))
shape: (3, 1)
┌───────────┐
│ foo       │
│ ---       │
│ list[i64] │
╞═══════════╡
│ [1, 2, 3] │
├╌╌╌╌╌╌╌╌╌╌╌┤
│ [4, 5, 6] │
├╌╌╌╌╌╌╌╌╌╌╌┤
│ [7, 8, 9] │
└───────────┘