convert repetitive lists as rows in pandas column

Viewed 20

I have a dataframe in pandas as mentioned below where list elements in column info is same as unique file in column id:

id   text         info
1    great        ['son','daughter']
1    excellent    ['son','daughter']
2    nice         ['father','mother','brother']
2    good         ['father','mother','brother']
2    bad          ['father','mother','brother']
3    awesome       nan

All I want to get list elements as row for each file, like:

id   text         info
1    great        son
1    excellent    daughter
2    nice         father
2    good         mother
2    bad          brother
3    awesome      nan
1 Answers

Let us try explode after drop_duplicates

df['info'] = df['info'].drop_duplicates().explode().values
df
Out[298]: 
   id       text      info
0   1      great       son
1   1  excellent  daughter
2   2       nice    father
3   2       good    mother
4   2        bad   brother
5   3    awesome       NaN
Related