繁体   English   中英

Python: TypeError: 'numpy.int64' object 不可迭代

[英]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

希望这可以帮助!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM