Skip to content

Latest commit

 

History

History
85 lines (59 loc) · 3.62 KB

File metadata and controls

85 lines (59 loc) · 3.62 KB
title Use ai.fix_grammar with pandas
description Learn how to correct the spelling, grammar, and punctuation of input text by using the ai.fix_grammar function with pandas.
ms.reviewer vimeland
ms.topic how-to
ms.date 11/13/2025
ms.search.form AI functions

Use ai.fix_grammar with pandas

The ai.fix_grammar function uses generative AI to correct the spelling, grammar, and punctuation of input text, with a single line of code.

Note

Overview

The ai.fix_grammar function extends the pandas Series class. To correct the spelling, grammar, and punctuation of each row of input, call the function on a pandas DataFrame text column.

The function returns a pandas Series that contains corrected text values, which can be stored in a new DataFrame column.

Syntax

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

Parameters

None

Returns

The function returns a pandas Series that contains corrected text for each input text row. If the input text is null, the result is null.

Example

# This code uses AI. Always review output for mistakes. 

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)

This example code cell provides the following output:

:::image type="content" source="../../media/ai-functions/fix-grammar-example-output.png" alt-text="Screenshot showing a data frame with a 'text' column and a 'corrections' column, which has the text from the text column with corrected grammar." lightbox="../../media/ai-functions/fix-grammar-example-output.png":::

Multimodal input

The ai.fix_grammar function supports file-based multimodal input. You can fix grammar in the content of PDFs and text files by setting column_type="path" when your column contains file path strings. For more information about supported file types and setup, see Use multimodal input with AI functions.

# This code uses AI. Always review output for mistakes.

custom_df["corrections"] = custom_df["file_path"].ai.fix_grammar(column_type="path")
display(custom_df)

Related content