Series.
transform
Call func on self producing a Series with transformed values.
func
Produced Series will have same axis length as self.
func (function, str, list or dict) –
to use for transforming the data. If a function (Function) –
either (must) –
when passed a Series or when passed to Series.apply. (work) –
combinations are (Accepted) –
function (-) –
string function name (-) –
list of functions and/or function names (-) –
[np.exp. 'sqrt'] (e.g.) –
dict of axis labels -> functions (-) –
names or list of such. (function) –
axis ({0 or 'index'}) – Parameter needed for compatibility with DataFrame.
dtype (numpy.dtype, default None) – Specify dtypes of returned DataFrames. See Notes for more details.
*args –
arguments to pass to func. (Keyword) –
**kwargs –
arguments to pass to func. –
Series
A Series that must have the same length as self.
:raises ValueError : If the returned Series has a different length than self.:
参见
Series.agg
Only perform aggregating type operations.
Series.apply
Invoke function on a Series.
提示
When deciding output dtypes and shape of the return value, Mars will try applying func onto a mock Series, and the transform call may fail. When this happens, you need to specify dtype of output Series.
dtype
实际案例
>>> import mars.tensor as mt >>> import mars.dataframe as md >>> df = md.DataFrame({'A': range(3), 'B': range(1, 4)}) >>> df.execute() A B 0 0 1 1 1 2 2 2 3 >>> df.transform(lambda x: x + 1).execute() A B 0 1 2 1 2 3 2 3 4
Even though the resulting Series must have the same length as the input Series, it is possible to provide several input functions:
>>> s = md.Series(range(3)) >>> s.execute() 0 0 1 1 2 2 dtype: int64 >>> s.transform([mt.sqrt, mt.exp]).execute() sqrt exp 0 0.000000 1.000000 1 1.000000 2.718282 2 1.414214 7.389056