This occurs because this pandas function doesn’t return anything back to Python (which is why you get a value of None), it only prints. The pandas documentation for df.info() offers a similar type of solution:
Pipe output of DataFrame.info to buffer instead of sys.stdout, get buffer content and writes to a text file:
>>> import io
>>> buffer = io.StringIO()
>>> df.info(buf=buffer)
>>> s = buffer.getvalue()
>>> with open("df_info.txt", "w",
... encoding="utf-8") as f:
... f.write(s)
In your case, you can probably do st.write(s) instead of writing to a file at the end.
I’m facing same issue, i created function which print a value
recommendation=anime_recommendation(anime_names)
if st.button("Recommend"):
recommendations=anime_recommendation(anime_names)
import io
buffer = io.StringIO()
recommendations(buf=buffer)
s = buffer.getvalue()
with open("recommendations.txt", "w",
encoding="utf-8") as f:
f.write(s)
it giving me this error:
TypeError: 'NoneType' object is not callable
Traceback:
File "c:\python39\lib\site-packages\streamlit\script_runner.py", line 354, in _run_script
exec(code, module.__dict__)
File "D:\projects\RecommendAnime\webapp\web_app.py", line 63, in <module>
recommendations(buf=buffer)