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 andfuncis applied per column; the output row count must match the input (transform semantics). UsesLiteFrameFunctional. Mirrorspandas.DataFrame.transformwhich defaults toaxis=0.axis=1: expression-based, per-row. The function receives each row and may return a dict or Series with any declared schema; usedtypesto name the output columns.
- Parameters:
func (callable or callable class) –
Function to apply. For
axis=0it receives a column (Series) and must return a transformed column of the same length. Foraxis=1it receives a single row and may return a dict or Series declaring any output schema viadtypes.If
funcis a class, it is instantiated once per chunk,__call__is invoked per column (axis=0) or per row (axis=1), andclose()(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.
0operates per column,1per 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 viadtypes(axis=1). Call.execute()to materialize.- Return type:
See also
applyApply a function per column or per row.
transform_chunkTransform per execution chunk.
mapApply 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) —funcreceives 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) —funcreceives each row as a Series and may return a dict with any declared schema. Declare the output schema withdtypes:>>> result = lf.transform(lambda row: {'ab': row['a'] + row['b']}, ... axis=1, dtypes={'ab': int}) >>> result.execute() ab 0 11 1 22 2 33