Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python相当于;grepl";有条件的_Python_R - Fatal编程技术网

python相当于;grepl";有条件的

python相当于;grepl";有条件的,python,r,Python,R,以下是R代码。我想知道python与下面代码的等价物是什么。特别是 grepl("dog|cat", data$animal) 部分守则 data <- data.frame(animal = sample(c("cat","dog","bird",'doggy','kittycat'), 10, replace = T)) ifelse(grepl("dog|cat", data$animal), "ke

以下是R代码。我想知道python与下面代码的等价物是什么。特别是

grepl("dog|cat", data$animal)
部分守则

data <- data.frame(animal = sample(c("cat","dog","bird",'doggy','kittycat'), 
                                       10, replace = T)) 
ifelse(grepl("dog|cat", data$animal), "keep", "discard")

数据对正则表达式使用
re
,在动物身上循环,并通过与
None
比较来测试是否存在匹配:

>>> animal = ["cat","dog","doggy","kittycat","bird","dog"]
>>> import re
>>> [re.search("cat|dog",a) is not None for a in animal]
[True, True, True, True, False, True]

python数据是什么样子的?一个列表,一个熊猫数据框?请添加设置示例数据的python代码。数据在列表中。。谢谢