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)
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.