Combine multiple rows of lists into one big list using pandas

Viewed 252

I have a pandas data frame with multiple lists. Is there any way to combine all of the lists from all rows ( there could be 100 rows ) into one big list?

     fruits
0    [apple, banana, orange]
1    [berry, lemon]
2    [apple, tomato]
3    [lime, orange, banana]

Expected Output

[ 'apple', 'banana', 'orange', 'berry', 'lemon', 'apple', 'tomato', 'lime', 'orange', 'banana' ] 

3 Answers

use df.explode()

lst = df['fruits'].explode().to_list()

Try extend :

result = []
for row in fruits :
    result.extend(row)
Related