相当于R运算符“%in%"的Python [英] Python equivalent of the R operator "%in%"

查看:90
本文介绍了相当于R运算符“%in%"的Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此运算符在python中的等效项是什么?我试图通过让行仅在行中的列具有在我的列表中找到的值的情况下保留行来筛选熊猫数据库.

What is the python equivalent of this in operator? I am trying to filter down a pandas database by having rows only remain if a column in the row has a value found in my list.

我尝试使用any(),但遇到了很大的困难.

I tried using any() and am having immense difficulty with this.

推荐答案

与R文档的熊猫比较是此处.

Pandas comparison with R docs are here.

s <- 0:4
s %in% c(2,4)

isin()方法类似于R%in%运算符:

The isin() method is similar to R %in% operator:

In [13]: s = pd.Series(np.arange(5),dtype=np.float32)

In [14]: s.isin([2, 4])
Out[14]: 
0    False
1    False
2     True
3    False
4     True
dtype: bool

这篇关于相当于R运算符“%in%"的Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆