python - 用 python 翻译数据框列

标签 python pandas dataframe google-translator-toolkit

我想将我的数据框列从法语翻译成英语。

 from googletrans import Translator 
 translator = Translator()         
 df = pd.DataFrame({'French':['ma voiture','Il fait beau aujourdhui']})
 df['English'] = df['French'].apply(translator.translate,src='fr',dest='en').apply(getattr, args=('text',))

我做了这些行,但我发现了一个错误。请问我该如何解决。?

最佳答案

嗯,我在使用 googletrans 时遇到了问题。但后来尝试了解决方案 here这建议做:

pip install googletrans-temp

而且您的代码似乎运行良好:

输出:

print (df)
                    French                         English
0               ma voiture                          my car
1  Il fait beau aujourdhui  Such a beautiful weather today

关于python - 用 python 翻译数据框列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55795705/

相关文章:

python - 使用python根据经度和纬度匹配两个数据集

python - 填充不保留所有列

python - Azure:使用 Python 创建公共(public) IP 地址

python - 非常奇怪的Python 3字节到字符串失败

python - 具有线性回归模型的 fillna 从数据框 pandas 中的两列构建

r - dply : order columns alphabetically in R

使用 dplyr 重复采样 data.frame

python - 在多个时间范围内聚合/重采样 pandas 多索引数据帧并预测 ARIMA

python - 打开 ZIP 文件,扫描其中的 CSV 文件并将某些内容传输到另一个 CSV 文件

python - 用相关列的平均值替换数据框中的 NaN 值的函数