[Solved] Split List of Sentences in a Pandas Dataframe Column into Separate Columns


You could use split etc. but it’s not very robust:

>>> s.str[2:-2].str.split("',\s*'", expand=True).add_prefix('rep')
                                        rep0  ...                                    rep2
1  f, they have everything i am looking for.  ...  q, i always find what I am looking for
2                           easy to navigate  ...            easy to use, very convenient

[2 rows x 3 columns]

The robust way to do it is ast.literal_eval, and then some pivoting:

>>> df = s.apply(ast.literal_eval).explode().rename('val').reset_index()
>>> df = df.join(df.groupby('index').cumcount().rename('rep').add(1)).pivot('index', 'rep', 'val').add_prefix('rep')
>>> df
rep                                         rep1  ...                                    rep3
index                                             ...                                        
1      f, they have everything i am looking for.  ...  q, i always find what I am looking for
2                               easy to navigate  ...            easy to use, very convenient

[2 rows x 3 columns]

solved Split List of Sentences in a Pandas Dataframe Column into Separate Columns