python相当于;grepl";有条件的
以下是R代码。我想知道python与下面代码的等价物是什么。特别是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
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代码。数据在列表中。。谢谢