pandas.Series.explode#
- Series.explode(ignore_index=False)[源代码]#
将类似列表的每个元素转换为一行。
- Parameters:
- ignore_indexbool,默认 False
如果为 True,则生成的索引将标记为 0, 1, …, n - 1。
- Returns:
- Series
将列表展开成行;索引将在这些行中重复。
参见
Series.str.split按指定分隔符分割字符串值。
Series.unstack将带有 MultiIndex 的 Series unstack(也称为 pivot)以生成 DataFrame。
DataFrame.melt将数据帧从宽格式转置为长格式。
DataFrame.explode将数据帧从列表状列展开为长格式。
Notes
此例程将展开类列表对象,包括列表、元组、集合、Series 和 np.ndarray。子行中的结果 dtype 将为 object。标量将保持不变,空类列表将导致该行出现 np.nan。此外,当展开集合时,输出的顺序将是非确定性的。
有关更多示例,请参阅 the user guide 。
Examples
>>> s = pd.Series([[1, 2, 3], 'foo', [], [3, 4]]) >>> s 0 [1, 2, 3] 1 foo 2 [] 3 [3, 4] dtype: object
>>> s.explode() 0 1 0 2 0 3 1 foo 2 NaN 3 3 3 4 dtype: object