1

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 3

7

use df.explode()

lst = df['fruits'].explode().to_list()
Sign up to request clarification or add additional context in comments.

Comments

4

Try:

df["fruits"].sum()

Comments

2

Try extend :

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.