将 ai.summarize 与 pandas 配合使用

ai.summarize 函数使用生成式 AI 生成输入文本摘要,并包含一行代码。 该函数可以从数据帧的一列汇总值,也可以汇总所有列中的值。

注释

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

概述

ai.summarize 函数扩展了 pandas Series 类。 若要单独汇总该列中的每一行值,请对 pandas DataFrame 文本列调用该函数。 还可以在整个 DataFrame 上调用 ai.summarize 函数,以汇总所有列的值。

该函数返回一个 pandas Series,其中包含摘要,这些摘要可以存储在新的 DataFrame 列中。

Syntax

df["summaries"] = df["text"].ai.summarize()

参数

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([
        ("Microsoft Teams", "2017",
        """
        The ultimate messaging app for your organization—a workspace for real-time 
        collaboration and communication, meetings, file and app sharing, and even the 
        occasional emoji! All in one place, all in the open, all accessible to everyone.
        """),
        ("Microsoft Fabric", "2023",
        """
        An enterprise-ready, end-to-end analytics platform that unifies data movement, 
        data processing, ingestion, transformation, and report building into a seamless, 
        user-friendly SaaS experience. Transform raw data into actionable insights.
        """)
    ], columns=["product", "release_year", "description"])

df["summaries"] = df["description"].ai.summarize()
display(df)

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

显示数据帧的屏幕截图。“摘要”列仅在相应的行中对“description”列进行了摘要。