ssert_frame_equal.html)
    * [ polars.testing.assert_frame_not_equal ](../../api/polars.testing.assert_frame_not_equal.html)
    * [ polars.testing.assert_series_equal ](../../api/polars.testing.assert_series_equal.html)
    * [ polars.testing.assert_series_not_equal ](../../api/polars.testing.assert_series_not_equal.html)
    * [ polars.testing.parametric.dataframes ](../../api/polars.testing.parametric.dataframes.html)
    * [ polars.testing.parametric.series ](../../api/polars.testing.parametric.series.html)
    * [ polars.testing.parametric.column ](../../api/polars.testing.parametric.column.html)
    * [ polars.testing.parametric.columns ](../../api/polars.testing.parametric.columns.html)
    * [ polars.testing.parametric.create_list_strategy ](../../api/polars.testing.parametric.create_list_strategy.html)
    * [ polars.testing.parametric.load_profile ](../../api/polars.testing.parametric.load_profile.html)
    * [ polars.testing.parametric.set_profile ](../../api/polars.testing.parametric.set_profile.html)

  * [ Metadata ](../../metadata.html) __
    * [ polars.build_info ](../../api/polars.build_info.html)
    * [ polars.get_index_type ](../../api/polars.get_index_type.html)
    * [ polars.show_versions ](../../api/polars.show_versions.html)
    * [ polars.thread_pool_size ](../../api/polars.thread_pool_size.html)
    * [ polars.threadpool_size ](../../api/polars.threadpool_size.html)

  * [ __ ](../../../index.html)
  * [ Python API reference ](../../index.html)
  * __
  * [ Functions ](../functions.html)
  * polars.map_batches 

#  polars.map_batches  #

polars.  map_batches  (

     _ exprs  :  Sequence  [  [ str  ](https://docs.python.org/3/library/stdtypes.html#str "\(in Python v3.12\)") ]  |  Sequence  [  Expr  ]  _ , 
     _ function  :  Callable  [  [  Sequence  [  Series  ]  ]  ,  Series  ]  _ , 
     _ return_dtype  :  PolarsDataType  |  [ None  ](https://docs.python.org/3/library/constants.html#None "\(in Python v3.12\)") =  None  _ , 
)  →  Expr  [ [source]  ](https://github.com/pola-rs/polars/blob/main/py-
polars/polars/functions/lazy.py#L855-L914) #

    

Map a custom function over multiple columns/expressions.

Produces a single Series result.

Parameters  :

    

**exprs**

    

Expression(s) representing the input Series to the function.

**function**

    

Function to apply over the input.

**return_dtype**

    

dtype of the output Series.

Returns  :

    

Expr

    

Expression with the data type given by ` return_dtype  ` .

Examples

    
    
    >>> def test_func(a, b, c):
    ...     return a + b + c
    >>> df = pl.DataFrame(
    ...     {
    ...         "a": [1, 2, 3, 4],
    ...         "b": [4, 5, 6, 7],
    ...     }
    ... )
    >>>
    >>> df.with_columns(
    ...     (
    ...         pl.struct(["a", "b"]).map_batches(
    ...             lambda x: test_func(x.struct.field("a"), x.struct.field("b"), 1)
    ...         )
    ...     ).alias("a+b+c")
    ... )
    shape: (4, 3)
    ┌─────┬─────┬───────┐
    │ a   ┆ b   ┆ a+b+c │
    │ --- ┆ --- ┆ ---   │
    │ i64 ┆ i64 ┆ i64   │
    ╞═════╪═════╪═══════╡
    │ 1   ┆ 4   ┆ 6     │
    │ 2   ┆ 5   ┆ 8     │
    │ 3   ┆ 6   ┆ 10    │
    │ 4   ┆ 7   ┆ 12    │
    └─────┴─────┴───────┘
    

[ __ previous  polars.map  ](polars.map.html "previous page") [ next
polars.map_groups  __ ](polars.map_groups.html "next page")

__ On this page

  * ` map_batches()  `

© Copyright 2020, Ritchie Vink.  

Created using [ Sphinx ](https://www.sphinx-doc.org/) 7.2.4.  

Built with the [ PyData Sphinx Theme ](https://pydata-sphinx-
theme.readthedocs.io/en/stable/index.html) 0.14.1.