Skip to main content
100%

[split pandas cell into rows]将一个包含字符串或 list 的 cell,使用特定字符,将 cell 分成多行, 同行其他 cells 复制值 #pandas

✓ Published0🌍 Public
SShawn91
Last edited Jan 25, 2019
Created on Nov 6, 2018

This example shows a pandas data-wrangling technique that transforms a DataFrame by splitting a single cell containing a delimited string or list into multiple rows while duplicating the other column values across the new rows. The function `splitDataFrameList` accepts a DataFrame, the target column name, and a separator string, then uses `df.apply` along the rows and a helper function to parse each cell. It relies on the `collections.Iterable` check and the `str.split` method to separate values, ultimately constructing a new DataFrame from the accumulated row dictionaries via `pd.DataFrame`.

AI-generated description

Similar vizzes