1

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.

Celius Stingher
  • 17,835
  • 6
  • 23
  • 53
Ir8_mind
  • 842
  • 5
  • 9

1 Answers1

3

This is what pandas' explode is here for!

df = df.explode('val')

Returns:

id       val
1         hi 
1      there
2     lovely
Celius Stingher
  • 17,835
  • 6
  • 23
  • 53