python-3.x - 替换 HTML 标签不会改变数据框
问题描述
我正在尝试从我的数据框对象列中删除 html 标签,但它不起作用。
df.site.replace(to_replace=['<a href="', '</a>'],value='',inplace=True )
Out df.site:
0 <a href="http://twitter.com/download/iphone" r...
1 <a href="http://twitter.com/download/iphone" r...
2 <a href="http://twitter.com/download/iphone" r...
3 <a href="http://twitter.com/download/iphone" r...
4 <a href="http://twitter.com/download/iphone" r...
当我运行它时,没有任何变化。为什么?
解决方案
df = pd.DataFrame({"site":['<a href="http://example.com"</a> this is not ']})
df.site = df.site.str.replace(pat=r'(<a href=")|("</a>)',repl = "")
df.site
http://example.com this is not
推荐阅读
- java - Android studio:如何在意图中传递自定义对象
- php - Unexpected result using OR operator in regular expression
- android - Android Studio 未检测到本地模块的更改
- c# - 为什么导航发生时连接插件网络处理程序不起作用
- python-3.x - Python中的多进程在逐行读取文件时比单进程慢4000倍,这是怎么回事?
- javascript - 如何在另一个插件调用的设置中存储插件方法调用而不在 jQuery 中执行它?
- python - Django模板多个表,数据仅稍作修改
- swift - 在 Xcode9.3.1 中配置 LinePhone
- javascript - 如何在 jQuery 上获得唯一的选择器
- openmdao - OpenMDAO:什么时候需要定义偏导数?