[英]Using the st.write() , st.text or st.markdown() in streamlit is displaying None
The code is given as -代码给出为 -
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
i tried other alternatives such as st.text or st.markdown but none of them are working its showing none each and every time我尝试了其他替代方案,例如 st.text 或 st.markdown,但它们都没有工作,每次都没有显示
As stated in the comment, you need to append without calling print such as:如评论中所述,您需要 append 而不调用打印,例如:
recommended_movies.append(movies.iloc[i[0]].title)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.