To explode list like column to row, we can use pandas explode() function. My pandas' version '0.25.3'
The given example worked for me and another answer of Stackoverflow.com works as expected but it doesn't work for my dataset.
city nested_city
0 soto ['Soto']
1 tera-kora ['Daniel']
2 jan-thiel ['Jan Thiel']
3 westpunt ['Westpunt']
4 nieuwpoort ['Nieuwpoort', 'Santa Barbara Plantation']
What I have tried:
test_data['nested_city'].explode()
and
test_data.set_index(['nested_city']).apply(pd.Series.explode).reset_index()
Output
0 ['Soto']
1 ['Daniel']
2 ['Jan Thiel']
3 ['Westpunt']
4 ['Nieuwpoort', 'Santa Barbara Plantation']
Name: neighbors, dtype: object
nested_cityis list or string ?test_data['nested_city'].apply(type)) or just string representation of a list in which case dotest_data['nested_city'].apply(ast.literal_eval).explode()type(test_data['nested_city'])returns, pandas.core.series.Series<class 'str'>, not list type, explode is for list typedf.joincheck documentation. I will leave it to you as a homework :)