我有一个名为fruit_list
的列表
[apple,orange,pineapple,banana,tomato]
我想将这个列表与名为fruits
的panda Dataframe 列进行匹配,并输出交集。
以及一个列名为fruits
的pandas Dataframe
fruits
[apple,mango]
[mango,cabbage,pineapple,carrot]
[egg,sandwich,orange,carrot,tomato]
预期产出
output
[apple]
[pineapple]
[orange,tomato]
如何有效地完成这一点的任何想法。谢谢!
3条答案
按热度按时间prdp8dxp1#
map
带过滤功能,我认为这是一个有效的解决方案xzabzqsa2#
您可以使用
apply
并定义function
:它返回以下内容:
qoefvg9y3#
使用
set.intersection
获取常见水果输出为