将ai.fix_grammar与 pandas 配合使用

ai.fix_grammar 函数使用生成 AI 通过一行代码更正输入文本的拼写、语法和标点符号。

注释

  • 本文介绍如何将 ai.fix_grammar 与 pandas 配合使用。 若要将 ai.fix_grammar 与 PySpark 配合使用,请参阅 本文
  • 请参阅 本概述文章中的其他 AI 函数。
  • 了解如何自定义 AI 函数的配置

概述

ai.fix_grammar 函数扩展了 pandas Series 类。 若要更正每行输入的拼写、语法和标点符号,请对 pandas DataFrame 文本列调用函数。

该函数返回一个 pandas Series,其中包含更正的文本值,这些值可以存储在新的 DataFrame 列中。

Syntax

df["corrections"] = df["input"].ai.fix_grammar()

参数

None

退货

该函数返回一个 pandas Series ,其中包含每个输入文本行的更正文本。 如果输入的文本是 null,则结果为 null

Example

# This code uses AI. Always review output for mistakes. 
# Read terms: https://azure.microsoft.com/support/legal/preview-supplemental-terms/.

df = pd.DataFrame([
        "There are an error here.",
        "She and me go weigh back. We used to hang out every weeks.",
        "The big picture are right, but you're details is all wrong."
    ], columns=["text"])

df["corrections"] = df["text"].ai.fix_grammar()
display(df)

此示例代码单元提供以下输出:

显示包含“text”列和“更正”列的数据帧的屏幕截图,其中包含具有更正语法的文本列中的文本。