maxframe.liteframe.LiteFrame.map#

LiteFrame.map(func, *, na_action=None, dtype=None, skip_infer=False, args=(), **kwargs)#

Apply func element-wise to every value in the LiteFrame.

Each cell is transformed independently by func; the output has the same shape and column names as the input. Output dtypes are inferred by mocking func on a sample value per column unless dtype is supplied or skip_infer is set.

Parameters:
  • func (callable or callable class) –

    Function to apply to each element.

    If func is a class, it is instantiated once per chunk, __call__ is invoked per element, and close() (if defined) is always called at the end of the chunk.

  • na_action (str, optional) – If ‘ignore’, null values are propagated without calling func.

  • dtype (dtype, optional) – Output dtype applied to all columns.

  • skip_infer (bool) – If True, skip mock inference when dtype is not provided.

  • args (tuple) – Positional arguments forwarded to func.

  • **kwargs – Keyword arguments. ‘_check_output_dtype’ is popped for output validation; all others are forwarded to func.

Returns:

Lazy LiteFrame with the same shape as the input, where each value is the result of applying func to the corresponding input cell. Call .execute() to materialize.

Return type:

LiteFrame

See also

apply

Apply a function per column or per row.

transform

Transform per column or per row.

Examples

>>> import maxframe.liteframe as mlf
>>> lf = mlf.LiteFrame({'a': [1, 2, 3], 'b': [10, 20, 30]})
>>> result = lf.map(lambda x: x * 2)
>>> result.execute()
   a   b
0  2  20
1  4  40
2  6  60

Specify an explicit output dtype with dtype:

>>> result = lf.map(lambda x: float(x), dtype='float64')
>>> result.execute()
     a     b
0  1.0  10.0
1  2.0  20.0
2  3.0  30.0