diff --git a/py-polars/polars/expr/struct.py b/py-polars/polars/expr/struct.py index 7b9429971537a..636bacdc188b9 100644 --- a/py-polars/polars/expr/struct.py +++ b/py-polars/polars/expr/struct.py @@ -126,6 +126,22 @@ def field(self, name: str | list[str], *more_names: str) -> Expr: │ 2 ┆ cd │ └─────┴─────┘ + Notes + ----- + The `struct` namespace has implemented `__getitem__` + so you can also access fields by index: + + >>> df.select(pl.col("struct_col").struct[1]) + shape: (2, 1) + ┌─────┐ + │ bbb │ + │ --- │ + │ str │ + ╞═════╡ + │ ab │ + │ cd │ + └─────┘ + """ if more_names: name = [*([name] if isinstance(name, str) else name), *more_names]