Skip to main content
Glama
expr_cat.py1.26 kB
from __future__ import annotations from typing import TYPE_CHECKING, Generic, TypeVar if TYPE_CHECKING: from narwhals.expr import Expr ExprT = TypeVar("ExprT", bound="Expr") class ExprCatNamespace(Generic[ExprT]): def __init__(self, expr: ExprT) -> None: self._expr = expr def get_categories(self) -> ExprT: """Get unique categories from column. Returns: A new expression. Examples: >>> import polars as pl >>> import narwhals as nw >>> df_native = pl.DataFrame( ... {"fruits": ["apple", "mango", "mango"]}, ... schema={"fruits": pl.Categorical}, ... ) >>> df = nw.from_native(df_native) >>> df.select(nw.col("fruits").cat.get_categories()).to_native() shape: (2, 1) ┌────────┐ │ fruits │ │ --- │ │ str │ ╞════════╡ │ apple │ │ mango │ └────────┘ """ return self._expr._with_elementwise_op( lambda plx: self._expr._to_compliant_expr(plx).cat.get_categories() )

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Lillard01/chatExcel-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server