我有一个像这样的 pandas 数据框:
我需要知道city
是否出现在citylist
的列表中(忽略大小写)。
我尝试像这样使用apply
,但无法找出正确的语法:
df.apply(lambda x: x['city'].lower() in x['citylist'])
最佳答案
传递参数axis=1
apply
逐行迭代:
In [49]:
df[df.apply(lambda x: x['city'].lower() in x['citylist'], axis=1)]
Out[49]:
city citylist
1 RESTON [reston, herndon]
4 SPRINGFIELD [springfield, west springfield]
关于python - 检查一列中的值是否在另一列的列表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32233069/