我的df
数据有两列,如下所示
thePerson theText
"the abc" "this is about the abc"
"xyz" "this is about tyu"
"wxy" "this is about abc"
"wxy" "this is about WXY"
我想要一个结果df
thePerson theText
"the abc" "this is about <b>the abc</b>"
"xyz" "this is about tyu"
"wxy" "this is about abc"
"wxy" "this is about <b>WXY</b>"
请注意,如果同一行中的文本包含人物,则文本中的人物将变为粗体。你知道吗
我尝试过的一个失败的解决方案是:
df['theText']=df['theText'].replace(df.thePerson,'<b>'+df.thePerson+'</b>', regex=True)
我想知道我是否可以用lapply
或map
来做这个
我的python环境设置为2.7版
您可以使用^{} :
使用
re.sub
和zip
复制/粘贴 您应该能够运行这个精确的代码并获得所需的结果
你应该看看这个
相关问题 更多 >
编程相关推荐