I am trying to translate text from Urdu to English using googletrans. I am getting this error message TypeError: 'numpy.int64' object is not iterable when I try to create a dictionary to translate the elements in the column cells. How do I fix this error? Thanks in advance.
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)
I have previously encountered the same issue. This bug has to deal with your for
statements. You might want to try changing your code to:
for column in range(unique_elements):
#add translation to the dictionary
Hope this helps!