I have a dataframe:
id val
1 ["hi", "there"]
2 ["lovely"]
How could I split list values in column into rows to get:
id val
1 hi
1 there
2 lovely
I have tried .melt()
but it didn't work.
I have a dataframe:
id val
1 ["hi", "there"]
2 ["lovely"]
How could I split list values in column into rows to get:
id val
1 hi
1 there
2 lovely
I have tried .melt()
but it didn't work.
This is what pandas' explode is here for!
df = df.explode('val')
Returns:
id val
1 hi
1 there
2 lovely