我如何将语言工具应用于 Python df 并将结果添加为 df 中的新列?
how do i apply language tool to Python df and add results as new column in df?
我正在尝试向 df 添加一列(大 Excel 导入为 df with Panda)。新列将是应用到 df 中的列时使用语言工具导入的输出错误。因此,对于每一行,我都会在新列 'Issues'
中出现错误或 blank/no 错误
import language_tool_python
import pandas as pd
tool = language_tool_python.LanguageTool('en-US')
fn = "Example.xlsx"
xlreader = pd.read_excel(fn, sheet_name="This is Starting File")
for row in xlreader:
text= str(xlreader[['Description']])
xlreader['Issues'] = tool.check(text)
以上导致 ValueError。
我也试过了,
xlreader['Issues'] = xlreader.apply(lambda x: tool.check(text))
结果是 NaN,尽管有错误。
有没有办法达到预期的效果?
期望的输出:
ID
Description
Added column 'Issues'
1-432
"The text withissues to check"
Possible spelling mistake
也许做这些改变:
转换为 str:
xlreader['Description'].astype('str')
要应用函数:
xlreader['Issues'] = xlreader['Description'].apply(lambda x: tool.check(x))
我正在尝试向 df 添加一列(大 Excel 导入为 df with Panda)。新列将是应用到 df 中的列时使用语言工具导入的输出错误。因此,对于每一行,我都会在新列 'Issues'
中出现错误或 blank/no 错误import language_tool_python
import pandas as pd
tool = language_tool_python.LanguageTool('en-US')
fn = "Example.xlsx"
xlreader = pd.read_excel(fn, sheet_name="This is Starting File")
for row in xlreader:
text= str(xlreader[['Description']])
xlreader['Issues'] = tool.check(text)
以上导致 ValueError。
我也试过了,
xlreader['Issues'] = xlreader.apply(lambda x: tool.check(text))
结果是 NaN,尽管有错误。
有没有办法达到预期的效果?
期望的输出:
ID | Description | Added column 'Issues' |
---|---|---|
1-432 | "The text withissues to check" | Possible spelling mistake |
也许做这些改变:
转换为 str:
xlreader['Description'].astype('str')
要应用函数:
xlreader['Issues'] = xlreader['Description'].apply(lambda x: tool.check(x))