我有一个数据框列描述。我想从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>"
<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>预期输出
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)发布于 2021-08-31 19:00:58
如果您的文本不复杂,则可以使用正则表达式删除<和>之间的任何内容
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 )来提取纯文本。
https://stackoverflow.com/questions/69003799
复制相似问题