我有一个Pandas DataFrame,是从读取csv文件得到的,在这个文件中有HTML标签,我想要移除它们。我希望使用BeautifulSoup来移除标签,因为它比使用简单的正则表达式如<.*?>更可靠。
通常我会通过执行以下代码来从字符串中移除HTML标签:
但是会返回以下错误:
通常我会通过执行以下代码来从字符串中移除HTML标签:
text = BeautifulSoup(text, 'html.parser').get_text()
现在我想对我的数据框中的每个元素进行这样的操作,所以我尝试了以下方法:
df.apply(lambda text: BeautifulSoup(text, 'html.parser').get_text())
但是会返回以下错误:
ValueError: ('The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().', 'occurred at index id')
print(df.head())
和print(df.columns)
,它们在说什么?如果没有这些信息,你的问题将无法解决。 - cs95