col, lit & concat#

col#

class TdCol[source]#

Bases: object

This class is used to create TableFrame column expressions.

An instance of this class is available as col. It can be called like a function (e.g., td.col(“name”)). For more information, refer to the __call__ method documentation.

This helper class provides an alternative way to create column expressions using attribute lookup. For instance, col.name is equivalent to col(“name”). Refer to __getattr__() method.

Example: >>> import tabsdata as td >>> >>> tf: td.TableFrame … >>> >>> tf = tf.with_columns(full_name=(td.col(“last_name”) + “, “ + >>> td.col(“first_name”))

lit#

lit(value: Any, dtype: PolarsDataType | None = None, *, allow_object: bool = False) td_expr.TdExpr[source]#

Expression for the given literal value.

Parameters:
  • value – The literal value.

  • dtype – The data type of the literal value.

  • allow_object – Whether to allow object data type.

Example:

>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf.select(td.lit("Hi").alias("lit"), td.col("age").alias("Age"))
>>>
┌──────┬──────┐
│ lit  ┆ Age  │
│ ---  ┆ ---  │
│ str  ┆ i64  │
╞══════╪══════╡
│ Hi   ┆ 1    │
│ Hi   ┆ 15   │
│ Hi   ┆ 18   │
│ Hi   ┆ null │
└──────┴──────┘

concat#

concat(items: Iterable[TdPolarsType]) TdPolarsType[source]#

Combine multiple TableFrames by stacking their rows.

Parameters:

items – The TableFrames to concatenate.

Example:

>>> import tabsdata as td
>>>
>>> tf1: td.TableFrame ...
>>>
┌──────┬──────┐
│ a    ┆ b    │
│ ---  ┆ ---  │
│ str  ┆ i64  │
╞══════╪══════╡
│ a    ┆ 1    │
│ b    ┆ 2    │
└──────┴──────┘
>>>
>>> tf2: td.TableFrame ...
>>>
┌──────┬──────┐
│ a    ┆ b    │
│ ---  ┆ ---  │
│ str  ┆ i64  │
╞══════╪══════╡
│ x    ┆ 10   │
│ y    ┆ 20   │
└──────┴──────┘
>>>
>>> tf = td.concat(tf1, tf2)
>>>
┌──────┬──────┐
│ a    ┆ b    │
│ ---  ┆ ---  │
│ str  ┆ i64  │
╞══════╪══════╡
│ a    ┆ 1    │
│ b    ┆ 2    │
│ x    ┆ 10   │
│ y    ┆ 20   │
└──────┴──────┘