首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从dataframe列替换</p&gt

从dataframe列替换</p&gt
EN

Stack Overflow用户
提问于 2021-08-31 18:34:44
回答 1查看 97关注 0票数 2

我有一个数据框列描述。我想从DataFrame列中删除文本"“&”“,只保留该文本。

代码语言:javascript
复制
     Description
     "<p>ID being used for RPA testing</p>"
     "This NUID is used for User Acceptance Testing of the RPA solutions for mainframe provisioning (ACF2 NP10 and all IDMS lower environments)<br>"
     <p>ID being used for RPA testing</p>
     This NUID is used for User Acceptance Testing of the RPA solutions for mainframe provisioning (ACF2 NP10 and all IDMS lower environments)<br>

预期输出

代码语言:javascript
复制
        Description
      ID being used for RPA testing
      This NUID is used for User Acceptance Testing of the RPA solutions for mainframe provisioning (ACF2 NP10 and all IDMS lower environments)
      ID being used for RPA testing
     This NUID is used for User Acceptance Testing of the RPA solutions for mainframe provisioning (ACF2 NP10 and all IDMS lower environments)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-08-31 19:00:58

如果您的文本不复杂,则可以使用正则表达式删除<>之间的任何内容

代码语言:javascript
复制
df = pd.DataFrame({
    "Description": [
        "<p>ID being used for RPA testing</p>",
        "This NUID is used for User Acceptance Testing of the RPA solutions for mainframe provisioning (ACF2 NP10 and all IDMS lower environments)<br>"
    ]
})

pattern = re.compile('<.+?(>|>)')
df["Description"] = df["Description"].str.replace(pattern, "")

对于更复杂的需求,您必须使用适当的超文本标记语言解析器(如BeautifulSoup )来提取纯文本。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69003799

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档