Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The ai.translate function translates each input row into the target language you choose.
Note
- This article covers
ai.translatewith pandas. For PySpark, see Use ai.translate with PySpark. - For all AI Functions and prerequisites, see AI Functions overview.
- Change default configuration for AI Functions with pandas.
Overview
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.
Syntax
df["translations"] = df["text"].ai.translate("target_language")
Parameters
| Name | Description |
|---|---|
to_lang Required |
A string representing the target language for text translations. |
Returns
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.
Example
# 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)
Output:
Multimodal input
To translate images, PDFs, or text files, set column_type="path" when the input column contains file path strings. For 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)
Related content
- Use ai.translate with PySpark.
- Learn more about AI Functions.
- Use multimodal input with AI Functions.
- Change default configuration for AI Functions with pandas.
- Understand billing for AI Functions.