0

Hi i have the following Data frame.

    Number            Text
0   [12, 3]          Apple
1   [2222, 4, 5]     Banana
2   [3]              Guava

I require to Set_index of the dataframe such that each entry in the Number columns has a row entry as follows

           Text
Number
12         Apple
3          Apple
2222       Banana
4          Banana
5          Banana
3          Guava

In a nutshell, to make a list the index and expanding each of its entries to a row.

1 Answers1

0

Try explode:

df.explode('Number').set_index('Number')
Quang Hoang
  • 146,074
  • 10
  • 56
  • 74