acidplyr.mutate_all

acidplyr.mutate_all(df: DataFrame, fun: Callable, *args: Any, **kwargs: Any) DataFrame

Apply a function to all columns of a DataFrame.

Parameters:
  • df (pd.DataFrame) – Input DataFrame.

  • fun (callable) – Function applied to each column (as a Series). Must return a Series or array of the same length.

  • *args – Additional positional arguments passed to fun.

  • **kwargs – Additional keyword arguments passed to fun.

Returns:

DataFrame with every column replaced by fun’s output. Raises if the result’s shape doesn’t match df.

Return type:

pd.DataFrame

Examples

>>> import pandas as pd
>>> df = pd.DataFrame({"a": [1, 2], "b": [3, 4]})
>>> mutate_all(df, lambda s: s * 2).to_dict("list")
{'a': [2, 4], 'b': [6, 8]}