mars.dataframe.Series.transform#
- Series.transform(func, convert_dtype=True, axis=0, *args, skip_infer=False, dtype=None, **kwargs)#
在自我身上调用
func生成一个具有转化值的 Series。生成的序列将具有与自身相同的轴长度。
- Parameters
函数 (-) –
要么 (必须) –
Series.apply. (当传递一个 Series 时工作 或 当传递给) –
是 (接受的组合) –
函数 –
名称 (- 字符串函数) –
names (- 列表 的 函数和/或函数) –
'sqrt'] (例如 [np.exp.) –
函数 (- 字典 of 轴标签 ->) –
如此。 (函数名称 或 列表) –
axis ({0 或 'index'}) – 与 DataFrame 兼容所需的参数。
dtype (numpy.dtype, 默认值为 None) – 指定返回的 DataFrames 的数据类型。有关更多详细信息,请参见 备注。
skip_infer (bool, 默认值为 False) – 当未指定 dtypes 或 output_type 时,是否推断数据类型。
*args – 传递给 func 的位置参数。
**kwargs – 传递给 func 的关键字参数。
- Returns
系列
一个必须与自身具有相同长度的系列。
:raises ValueError : 如果返回的 Series 与自身长度不同。
另请参阅
Series.agg仅执行聚合类型操作。
Series.apply在序列上调用函数。
备注
在决定输出数据类型和返回值的形状时,Mars将尝试将
func应用到一个模拟的 Series 上,transform 方法可能会失败。当这种情况发生时,您需要指定输出 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
尽管生成的序列必须与输入序列具有相同的长度,但可以提供多个输入函数:
>>> 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