Python: TypeError: 'numpy.int64' object is not iterable
Python: TypeError: 'numpy.int64' object is not iterable
我正在尝试使用 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)
我以前遇到过同样的问题。此错误必须处理您的 for
语句。您可能想尝试将代码更改为:
for column in range(unique_elements):
#add translation to the dictionary
希望对您有所帮助!
我正在尝试使用 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)
我以前遇到过同样的问题。此错误必须处理您的 for
语句。您可能想尝试将代码更改为:
for column in range(unique_elements):
#add translation to the dictionary
希望对您有所帮助!