【发布时间】:2020-02-09 12:35:39
【问题描述】:
我有一个充满英文文本的 excel 表,所以现在我想将每个文本转换为其他语言(例如:法语)并使用 python 插入到 excel 表的下一列中。
那么如何处理呢?
我目前正在浏览 python 的 pandas。
【问题讨论】:
标签: python excel pandas language-translation google-translation-api
我有一个充满英文文本的 excel 表,所以现在我想将每个文本转换为其他语言(例如:法语)并使用 python 插入到 excel 表的下一列中。
那么如何处理呢?
我目前正在浏览 python 的 pandas。
【问题讨论】:
标签: python excel pandas language-translation google-translation-api
这应该可行。确保你pip install googletrans-temp
import pandas as pd
from googletrans import Translator
# read from an excel file
df = pd.read_excel('/Users/andrewgreatorex/Downloads/test_spreadsheet.xlsx')
# translate a column to French, and add back into the DataFrame
translator = Translator()
df['French'] = df['text'].apply(translator.translate,src='en',dest='fr').apply(getattr, args=('text',))
# output new excel file
df.to_excel('name_of_your_output_file.xlsx')
【讨论】: