我有一个叫做python框架的列
此栏应有认证数据:“10/10/2011”
或者说:“未经认可”
但在大多数未经认证的情况下,该专栏都会有一些文本,例如:
“这家企业没有经过认证……”
我想替换全文,只写:“未经认证”
现在,我写了一个函数:
def notAcredited(string):
if ('Not' in string or 'not' in string):
return 'Not Accredited'
我用一个循环来实现这个函数,可以用“.apply”方法来实现吗?在
^{pr2}$
Tags:
可以使用矢量化字符串方法^{} :
传递给} 接受的类型相同。regex模式中的
replace
的第一个参数,例如r'(?i).*not.*'
,可以是任何regex pattern。第二个可以是任何regex替换值,与^{(?i)
使模式不区分大小写,因此not
、Not
、NOt
、NoT
等都匹配。在Series.str.replace
将对re.sub
的调用循环化(这使得它比使用apply
实现的更快,因为apply
使用Python循环。)相关问题 更多 >
编程相关推荐