| title | Use ai.translate with pandas |
|---|---|
| description | Learn how to use the ai.translate function to translate input text into a new language of your choice with pandas. |
| ms.reviewer | vimeland |
| ms.topic | how-to |
| ms.date | 11/13/2025 |
| ms.search.form | AI functions |
The ai.translate function uses generative AI to translate input text into a new language (of your choice), with a single line of code.
Note
- This article covers using ai.translate with pandas. To use ai.translate with PySpark, see this article.
- See other AI functions in this overview article.
- Learn how to customize the configuration of AI functions.
The ai.translate function extends the pandas Series class. To translate each input row into a target language of your choice, call the function on a pandas DataFrame text column.
The function returns a pandas Series that contains translations, which you can store in a new DataFrame column.
Tip
The ai.translate function was tested with 10 languages: Czech, English, Finnish, French, German, Greek, Italian, Polish, Spanish, and Swedish. Your results with other languages might vary.
df["translations"] = df["text"].ai.translate("target_language")| Name | Description |
|---|---|
to_lang Required |
A string representing the target language for text translations. |
The function returns a pandas Series that contains translations for each row of input text. If the input text is null, the result is null.
# This code uses AI. Always review output for mistakes.
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)This example code cell provides the following output:
:::image type="content" source="../../media/ai-functions/translate-example-output.png" alt-text="Screenshot of a data frame with columns 'text' and 'translations'. The 'translations' column contains the text translated to Spanish." lightbox="../../media/ai-functions/translate-example-output.png":::
The ai.translate function supports file-based multimodal input. You can translate the content of images, 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["chinese_version"] = custom_df["file_path"].ai.translate(
"Chinese",
column_type="path",
)
display(custom_df)-
Detect sentiment with ai.analyze_sentiment.
-
Categorize text with ai.classify.
-
Generate vector embeddings with ai.embed.
-
Extract entities with ai_extract.
-
Fix grammar with ai.fix_grammar.
-
Answer custom user prompts with ai.generate_response.
-
Calculate similarity with ai.similarity.
-
Summarize text with ai.summarize.
-
Learn more about the full set of AI functions.
-
Customize the configuration of AI functions.
-
Did we miss a feature you need? Suggest it on the Fabric Ideas forum.