w3resource

Pandas Series: transform() function

Call function on self producing a Series in Pandas

The transform() function is used to call function on self producing a Series with transformed values and that has the same axis length as self.

Syntax:

Series.transform(self, func, axis=0, *args, **kwargs)
Pandas Series transform image

Parameters:

Name Description Type/Default Value Required / Optional
func Function to use for transforming the data. If a function, must either work when passed a Series or when passed to Series.apply.
Accepted combinations are:

  • function
  • string function name
  • list of functions and/or function names, e.g. [np.exp. 'sqrt']
  • dict of axis labels -> functions, function names or list of such.
unction, str, list or dict Required
axis Parameter needed for compatibility with DataFrame {0 or ‘index’} Required
args Positional arguments to pass to func.   Required
**kwds Keyword arguments to pass to func.   Required

Returns:Series
A Series that must have the same length as self.

Raises: ValueError- If the returned Series has a different length than self.

Example:


Download the above Notebook from here.



Inviting useful, relevant, well-written and unique guest posts