maxframe.liteframe.LiteFrame.transform#

LiteFrame.transform(func, axis=0, *, input_frame_type='pandas', dtypes=None, skip_infer=False, args=(), **kwargs)#

Transform per column (axis=0, default) or per row (axis=1).

  • axis=0 (default): operator-based, per-column. Columns are concatenated and func is applied per column; the output row count must match the input (transform semantics). Uses LiteFrameFunctional. Mirrors pandas.DataFrame.transform which defaults to axis=0.

  • axis=1: expression-based, per-row. The function receives each row and may return a dict or Series with any declared schema; use dtypes to name the output columns.

Parameters:
  • func (callable or callable class) –

    Function to apply. For axis=0 it receives a column (Series) and must return a transformed column of the same length. For axis=1 it receives a single row and may return a dict or Series declaring any output schema via dtypes.

    If func is a class, it is instantiated once per chunk, __call__ is invoked per column (axis=0) or per row (axis=1), and close() (if defined) is always called at the end of the chunk — even when __call__ receives single rows/columns.

  • axis ({0, 1}, default 0) – Axis along which to transform. 0 operates per column, 1 per row.

  • input_frame_type ({"pandas", "polars"}, default "pandas") – Frame type passed to func.

  • dtypes (dict or pd.Series, optional) – Expected output dtypes.

  • skip_infer (bool, default False) – If True, skip dtype inference.

  • args (tuple) – Extra positional arguments forwarded to func.

  • **kwargs – Extra keyword arguments forwarded to func.

Returns:

Lazy LiteFrame with the same row count as the input (axis=0) or a schema declared via dtypes (axis=1). Call .execute() to materialize.

Return type:

LiteFrame

See also

apply

Apply a function per column or per row.

transform_chunk

Transform per execution chunk.

map

Apply a function element-wise.

Examples

>>> import maxframe.liteframe as mlf
>>> lf = mlf.LiteFrame({'a': [1, 2, 3], 'b': [10, 20, 30]})

Transform per column (axis=0, default) — func receives each column as a Series and must return a same-length Series:

>>> result = lf.transform(lambda col: col * 2)
>>> result.execute()
   a   b
0  2  20
1  4  40
2  6  60

Transform per row (axis=1) — func receives each row as a Series and may return a dict with any declared schema. Declare the output schema with dtypes:

>>> result = lf.transform(lambda row: {'ab': row['a'] + row['b']},
...                       axis=1, dtypes={'ab': int})
>>> result.execute()
   ab
0  11
1  22
2  33