Google Colab中的大熊猫分裂翻译结果
我正在使用Google Colab和Pandas在CSV/Excel文件中进行单词的traslation,这是我的代码:
import pandas as pd
from googletrans import Translator
# read from an excel file
df = pd.read_excel('/content/Libro2.xlsx')
translator = Translator()
df = df.apply(translator.translate,src='en',dest='es').apply(getattr, args=('text',))
我的输出是在特定df = df.apply中使用此行(Translator.translate,src ='en',dest ='es')。 'text',))
,所以这里的问题是我要获得CSV文件的格式,我想以输入的格式来keet,所以我想让我的数据框架导出像往常一样进入CSV。这是我的输出:
我想拥有的输出就像第一张图像以防万一我的问题不清楚。
I'm doing a traslation of words in csv/excel files using Google Colab and Pandas here is my code:
import pandas as pd
from googletrans import Translator
# read from an excel file
df = pd.read_excel('/content/Libro2.xlsx')
translator = Translator()
df = df.apply(translator.translate,src='en',dest='es').apply(getattr, args=('text',))
So basically my input from excel is this one:
My output is this with this line in specific df = df.apply(translator.translate,src='en',dest='es').apply(getattr, args=('text',))
so the problem here is I'm getting the format for a csv file, I would like to keet it with the format of the input, so I would like to have my data frame to export in to csv as usual. Here is my output:
The output that I would like to have is like the first image just in case is not clear my issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您需要应用函数 elementwise ,则可以使用pandas
applymap
。输出 df_tr
If you need to apply the function elementwise, you can use Pandas
applymap
.Output df_tr