I have a pandas dataframe in which one column of text strings contains comma-separated values. I want to split each CSV field and create a new row per entry (as
pandas dataframe
The string function split can take an option boolean argument 'expand'.
Here is a solution using this argument:
(a.var1 .str.split(",",expand=True) .set_index(a.var2) .stack() .reset_index(level=1, drop=True) .reset_index() .rename(columns={0:"var1"}))