【发布时间】:2020-10-28 16:48:35
【问题描述】:
我正在尝试使用 googletrans 将文本从乌尔都语翻译成英语。当我尝试创建字典来翻译列单元格中的元素时,我收到此错误消息 TypeError: 'numpy.int64' object is not iterable。如何修复此错误?提前致谢。
translations = {}
for column in df_en.columns:
# unique elements of the column
unique_elements = df_en[column].unique()
for element in unique_elements:
# add translation to the dictionary
translations[element] = translator.translate(element).text
# modify all the terms of the data frame by using the previously created dictionary
df_en.replace(translations, inplace = True)
print(translations)
【问题讨论】:
-
你能检查你的代码意图吗?
-
尝试打印
unique_elements -
哪一行引发了错误?
标签: python dictionary typeerror google-translate translate