该 ai.translate 函数使用生成式 AI 将输入文本翻译为新语言(所选语言),只需一行代码。
注释
概述
ai.translate 函数扩展了 pandas Series 类。 若要将每个输入行转换为所选的目标语言,请在 pandas DataFrame 文本列中调用该函数。
该函数返回一个包含翻译的 pandas Series,你可以将其存储在新的 DataFrame 列中。
小窍门
函数 ai.translate 使用 10 种语言进行测试:捷克语、英语、芬兰语、法语、德语、希腊语、意大利语、波兰语、西班牙语和瑞典语。 其他语言的结果可能会有所不同。
Syntax
df["translations"] = df["text"].ai.translate("target_language")
参数
| Name | Description |
|---|---|
to_lang 必选 |
表示文本翻译的目标语言的字符串。 |
退货
该函数返回一个 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([
"Hello! How are you doing today?",
"Tell me what you'd like to know, and I'll do my best to help.",
"The only thing we have to fear is fear itself."
], columns=["text"])
df["translations"] = df["text"].ai.translate("spanish")
display(df)
此示例代码单元提供以下输出:
相关内容
使用 ai.analyze_sentiment检测情绪。
使用 ai.classify 对文本进行分类。
使用 ai_extract提取实体。
使用 ai.fix_grammar修复语法。
使用 ai.generate_response回答自定义用户提示。
使用ai.summarize功能汇总文本。
详细了解 完整的 AI 函数集。
自定义 AI 函数的配置。
我们错过了所需的功能吗? 在面料创意论坛上提出建议。