pandas.DataFrame.transform¶
-
DataFrame.
transform
(func, *args, **kwargs)[source]¶ Call function producing a like-indexed NDFrame and return a NDFrame with the transformed values
New in version 0.20.0.
Parameters: func : callable, string, dictionary, or list of string/callables
To apply to column
Accepted Combinations are:
- string function name
- function
- list of functions
- dict of column names -> functions (or list of functions)
Returns: - transformed : NDFrame
See also
pandas.NDFrame.aggregate
,pandas.NDFrame.apply
Examples
>>> df = pd.DataFrame(np.random.randn(10, 3), columns=['A', 'B', 'C'], ... index=pd.date_range('1/1/2000', periods=10)) df.iloc[3:7] = np.nan
>>> df.transform(lambda x: (x - x.mean()) / x.std()) A B C 2000-01-01 0.579457 1.236184 0.123424 2000-01-02 0.370357 -0.605875 -1.231325 2000-01-03 1.455756 -0.277446 0.288967 2000-01-04 NaN NaN NaN 2000-01-05 NaN NaN NaN 2000-01-06 NaN NaN NaN 2000-01-07 NaN NaN NaN 2000-01-08 -0.498658 1.274522 1.642524 2000-01-09 -0.540524 -1.012676 -0.828968 2000-01-10 -1.366388 -0.614710 0.005378