简体   繁体   English

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

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

相关问题 Streamlit - 无法使用 st.write() 重复表情符号字符串 - Streamlit - Cannot repeat emoji string using st.write() 是否可以在 streamlit 中创建像这样的不可编辑的文本框? St.write 只会写,但我需要在文本框中 - Is it possible to create a non-editable text box like this in streamlit ? St.write would only write but i need it in a text box streamlit st.info 信息框中的文本对齐 - Text align in streamlit st.info information box 如何使用 st.file_uploader 在 Streamlit 上上传大文件 - How to upload large files on Streamlit using st.file_uploader 我如何将 st.columns 与 st.tabs 一起使用(Streamlit) - How can ı use st.columns with st.tabs (Streamlit) 怎么躲”<na> " Streamlit 中带有 st.dataframe() 或 st.table() 的 (NaN) 值?</na> - How can I hide "<NA>" (NaN) values with st.dataframe() or st.table() in Streamlit? 创建sublime文本插件支持ST2和ST3 - Create sublime text plugin support both ST2 and ST3 KeyError: 'st.session_state 在 Streamlit 中没有密钥 - KeyError: 'st.session_state has no key in Streamlit 错误:无效的要求:&#39;import streamlit as st&#39; - requirements.txt - ERROR: Invalid requirement: 'import streamlit as st' - requirements.txt KeyError: 'st.session_state 在 Streamlit 中没有键 - KeyError: 'st.session_state has no key in Streamlit
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM