【发布时间】:2022-01-02 03:38:56
【问题描述】:
我正在尝试解码熊猫数据框中的 html 字符。 我不知道为什么,但是我的应用功能不起作用。
# requirements
import html
import pandas as pd
# This code works fine.
df = df.apply(lambda x: x + "TESTSTRING")
print(df) # "TESTSTRING" is appended to all values.
# This code also works fine. html.unescape() is working well.
fn = lambda x: html.unescape(x)
str = "Someting wrong with <b>E&S</b>"
print(fn(str)) # returns "Something wrong with <b>E&S</b>"
# However, the code below doesn't work. The "&" within the values dont' get decoded.
df2 = df.apply(fn)
print(df2) # The html characters aren't decoded!
apply 函数和 html.unescape() 分开运行很好,不知道为什么在一起就不行。
我也试过axis=1
非常感谢您的帮助。提前致谢。
【问题讨论】: