[Python] Getting error 'numpy.float64' object not iterable

Discussão em 'Python' iniciado por Stack, Junho 12, 2025.

  1. Stack

    Stack Membro Participativo

    While executing recommend() function i am getting error at line

    movies_list = sorted([enumerate(distances[0])], reverse=True, key = lambda x:x[1])[1:6]


    The following is the code I tried. please suggest changes in it:

    def recommend1(movie):
    movie_index = new_df[new_df['title']== movie].index[0]
    distances = similarity[movie_index]
    movies_list = sorted([enumerate(distances[0])], reverse=True , key = lambda x:x[1])[1:6]

    for i in movies_list :
    print(new_df.iloc[i[0]].title)


    Output after executing following statement: recommend1('Avatar')

    Error I got:

    TypeError Traceback (most recent call last)
    <ipython-input-63-76a841473d9d> in <module>
    ----> 1 recommend1('Avatar')

    <ipython-input-61-27f7c47f4ecd> in recommend1(movie)
    2 movie_index = new_df[new_df['title']== movie].index[0]
    3 distances = similarity[movie_index]
    ----> 4 movies_list = sorted([enumerate(distances[0])], reverse=True , key = lambda x:x[1])[1:6]
    5
    6 for i in movies_list :

    TypeError: 'numpy.float64' object is not iterable`

    Continue reading...

Compartilhe esta Página