w3resource

Pandas DataFrame - transform() function

DataFrame - transform() function

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

Syntax:

DataFrame.transform(self, func, axis=0, *args, **kwargs)

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 DataFrame or when passed to DataFrame.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.
function, str, list or dict Required
axis  If 0 or ‘index’: apply function to each column. If 1 or ‘columns’: apply function to each row. {0 or ‘index’, 1 or ‘columns’}
Default Value: 0
Required
*args Positional arguments to pass to func.   Required
**kwargs Keyword arguments to pass to func.   Required

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

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

Example:


Download the Pandas DataFrame Notebooks from here.

Previous: DataFrame - aggregate() function
Next: DataFrame - groupby() function



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/pandas/dataframe/dataframe-transform.php