mars.dataframe.DataFrame.explode#
- DataFrame.explode(column, ignore_index=False)#
Transform each element of a list-like to a row, replicating index values.
- 参数
- 返回
Exploded lists to rows of the subset columns; index will be duplicated for these rows.
- 返回类型
- 引发
ValueError : – if columns of the frame are not unique.
参见
DataFrame.unstack
Pivot a level of the (necessarily hierarchical) index labels.
DataFrame.melt
Unpivot a DataFrame from wide format to long format.
Series.explode
Explode a DataFrame from list-like columns to long format.
提示
This routine will explode list-likes including lists, tuples, Series, and np.ndarray. The result dtype of the subset rows will be object. Scalars will be returned unchanged. Empty list-likes will result in a np.nan for that row.
实际案例
>>> import mars.tensor as mt >>> import mars.dataframe as md >>> df = md.DataFrame({'A': [[1, 2, 3], 'foo', [], [3, 4]], 'B': 1}) >>> df.execute() A B 0 [1, 2, 3] 1 1 foo 1 2 [] 1 3 [3, 4] 1
>>> df.explode('A').execute() A B 0 1 1 0 2 1 0 3 1 1 foo 1 2 NaN 1 3 3 1 3 4 1