[英]how do i apply language tool to Python df and add results as new column in df?
I am trying to add a column to a df (large Excel imported as df with Panda).我正在尝试向 df 添加一列(大 Excel 导入为 df with Panda)。 The new column would be the output errors of using Language Tool import when applied to a column in the df.新列将是 output 应用于 df 中的列时使用语言工具导入的错误。 So for each row, I'd have the errors or blank/no errors in new column 'Issues'因此,对于每一行,我都会在新列“问题”中出现错误或空白/无错误
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)
The above results in a ValueError.以上结果导致 ValueError。
I also tried,我也试过,
xlreader['Issues'] = xlreader.apply(lambda x: tool.check(text))
The result was NaN, even though there are errors.结果是 NaN,即使有错误。
Is there a way to accomplish the desired output?有没有办法完成所需的 output?
Desired output:所需的 output:
ID ID | Description描述 | Added column 'Issues'添加了“问题”列 |
---|---|---|
1-432 1-432 | "The text withissues to check" “需要检查的文本” | Possible spelling mistake可能的拼写错误 |
Maybe do thé changes:也许做这些改变:
To cast as str:投射为海峡:
xlreader['Description'].astype('str')
To apply the function:申请function:
xlreader['Issues'] = xlreader['Description'].apply(lambda x: tool.check(x))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.