简体   繁体   English

我如何将语言工具应用于 Python df 并将结果添加为 df 中的新列?

[英]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.

相关问题 Python:将df的行数添加到另一个df作为新列 - Python: Add Count of Rows from df to Another df as New Column 我想知道如何遍历df.column3在df.column2中找到匹配项,并根据匹配将df.column1的名称添加到新列df.column4中 - I would like to know how to iterate through df.column3 find match in df.column2 and add name of df.column1 based on matches to a new column df.column4 如何向 dataframe (df1) 添加一个新列,这是另一个 dataframe (df2) 中 df1 的多个查找值的总和 - How can I add a new column to a dataframe (df1) that is the sum of multiple lookup values from df1 in another dataframe (df2) 当我将 function 应用于 DF 以创建多个新列时,我得到不同的结果,具体取决于我提交的 DF 中的行数 - When I apply a function to a DF to create multiple new columns, I get different results depending how many rows are in the DF I submit 如何将 df 列的 .describe() 输出写入新的 df? - How can I write the output of .describe() for a df column to a new df? 如何使用for循环和从其他df派生的新列名重命名df的列? - How do I rename columns of a df with a for loop and new column names deriving from other df? 如何通过有条件地查找另一个 DF 并将结果水平附加到新的 DF 中来创建 DF? - How can I create a DF by conditionally looking up into another DF, and appending the results horizontally into a new DF? 如何在python / pandas中将一个df列中的字符串添加到另一个? - How do I add a piece of string from one df column to another in python/pandas? Python & Pandas:将评分函数应用于 df 新列不起作用 - Python & Pandas: apply scoring function to df new column not working 如果 df2 中不存在列,如何将列从 df1 添加到 df2,否则什么也不做 - How to add a column from df1 to df2 if it not present in df2, else do nothing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM