mars.dataframe.Series.transform#

Series.transform(func, convert_dtype=True, axis=0, *args, skip_infer=False, dtype=None, **kwargs)#

Call func on self producing a Series with transformed values.

Produced Series will have same axis length as self.

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

  • function (-) –

  • either (must) –

  • Series.apply. (work when passed a Series or when passed to) –

  • are (Accepted combinations) –

  • function

  • name (- string function) –

  • names (- list of functions and/or function) –

  • 'sqrt'] (e.g. [np.exp.) –

  • functions (- dict of axis labels ->) –

  • such. (function names or list of) –

  • 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.

  • skip_infer (bool, default False) – Whether infer dtypes when dtypes or output_type is not specified.

  • *args – Positional arguments to pass to func.

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

Returns

  • Series

  • A Series that must have the same length as self.

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

See also

Series.agg

Only perform aggregating type operations.

Series.apply

Invoke function on a Series.

Notes

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.

Examples

>>> 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