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' ]
CodePudding user response:
use df.explode()
lst = df['fruits'].explode().to_list()
CodePudding user response:
Try:
df["fruits"].sum()
CodePudding user response:
Try extend :
result = []
for row in fruits :
result.extend(row)