mars.dataframe.DataFrame.map_chunk#
- DataFrame.map_chunk(func, args=(), kwargs=None, skip_infer=False, **kw)#
将函数应用于每个块。
- Parameters
- Returns
对DataFrame或Series每个块应用
func的结果。- Return type
另请参阅
DataFrame.apply执行任何类型的操作。
示例
>>> import mars.dataframe as md >>> df = md.DataFrame([[4, 9]] * 3, columns=['A', 'B']) >>> df.execute() A B 0 4 9 1 4 9 2 4 9
输出类型包括 Series 或 DataFrame 将自动推断。
>>> df.map_chunk(lambda c: c['A'] + c['B']).execute() 0 13 1 13 2 13 dtype: int64
如果自动推断失败,您可以自行指定
output_type。>>> import pandas as pd >>> import numpy as np >>> df['c'] = ['s1', 's2', 's3'] >>> df.map_chunk(lambda c: pd.concat([c['A'], c['c'].str.slice(1).astype(int)], axis=1)).execute() Traceback (most recent call last): TypeError: Cannot determine `output_type`, you have to specify it as `dataframe` or `series`... >>> df.map_chunk(lambda c: pd.concat([c['A'], c['c'].str.slice(1).astype(int)], axis=1), >>> output_type='dataframe', dtypes=pd.Series([np.dtype(object), np.dtype(int)])).execute() A c 0 4 1 1 4 2 2 4 3