pandas 在streamlit中使用st.write()、st.text或st.markdown()显示无

jjhzyzn0  于 2022-12-16  发布在  其他
关注(0)|答案(1)|浏览(282)

代码如下-

import streamlit as st
import pickle
import pandas as pd

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

    recommended_movies = []
    for i in movies_list:
        recommended_movies.append(print(movies.iloc[i[0]].title))
    return recommended_movies

movies_dict = pickle.load(open('movie_dict.pkl', 'rb'))
movies = pd.DataFrame(movies_dict)

similarity = pickle.load(open('similarity.pkl', 'rb'))

st.title('Movie Recommender System')

selected_movie_name = st.selectbox(
'Hey ! Wanna watch a movie ? Tell us the last movie you watched -',
movies['title'].values)

if st.button('Recommend'):
    recommendations = recommend(selected_movie_name)
    for i in recommendations :
        st.write(i)  #### This is what i'm talking about

我试过其他的选择,如sttext或stmarkdown,但没有一个是工作的,它显示没有每一次

3wabscal

3wabscal1#

如注解中所述,您需要在不调用print的情况下进行追加,例如:

recommended_movies.append(movies.iloc[i[0]].title)

相关问题