You are viewing documentation about an older version (1.18.0). View latest version

modin.pandas.DataFrame.transform¶

DataFrame.transform(func: Callable[[Any], Any], axis: Union[int, Literal['index', 'columns', 'rows']] = 0, *args: Any, **kwargs: Any) → DataFrame[source]¶

Call func on self producing a Snowpark pandas DataFrame with the same axis shape as self.

Parameters:
  • func (function, str, list-like or dict-like) –

    Function to use for transforming the data. If a function, must either work when passed a DataFrame or when passed to DataFrame.apply. If func is both list-like and dict-like, dict-like behavior takes precedence.

    Snowpark pandas currently only supports callable arguments, and does not yet support string, dict-like, or list-like arguments.

  • axis ({0 or 'index', 1 or 'columns'}, default 0) –

    If 0 or ‘index’: apply function to each column. If 1 or ‘columns’: apply function to each row.

    Snowpark pandas currently only supports axis=1, and does not yet support axis=0.

  • *args – Positional arguments to pass to func.

  • **kwargs – Keyword arguments to pass to func.

Examples

Increment every value in DataFrame by 1.

>>> d1 = {'col1': [1, 2, 3], 'col2': [3, 4, 5]}
>>> df = pd.DataFrame(data=d1)
>>> df
   col1  col2
0     1     3
1     2     4
2     3     5
>>> df.transform(lambda x: x + 1, axis=1)
   col1  col2
0     2     4
1     3     5
2     4     6
Copy

Apply a numpy ufunc to every value in the DataFrame.

>>> df.transform(np.square, axis=1)
   col1  col2
0     1     9
1     4    16
2     9    25
Copy