Discovered Streamlit today, going down the Get Started section, but Pandas with styler example does not work.
Steps to reproduce
I am talking about this example:
Code snippet:
import streamlit as st
import numpy as np
import pandas as pd
dataframe = pd.DataFrame(
np.random.randn(10, 20),
columns=('col %d' % i for i in range(20)))
st.dataframe(dataframe.style.highlight_max(axis=0))
Expected behavior:
Expected to see a dataframe in the browser.
Actual behavior:
Instead, I get: KeyError:âwarningsâ
Followed by a long Traceback:
File "C:\programs\gttools\python3\3.10.5\lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 564, in _run_script
exec(code, module.__dict__)
File "C:\Users\salazag\programs\streamlit\htp3\htp3.py", line 10, in <module>
dataframe = pd.DataFrame(
File "C:\programs\gttools\python3\3.10.5\lib\site-packages\pandas\core\frame.py", line 721, in __init__
mgr = ndarray_to_mgr(
File "C:\programs\gttools\python3\3.10.5\lib\site-packages\pandas\core\internals\construction.py", line 345, in ndarray_to_mgr
index, columns = _get_axes(
File "C:\programs\gttools\python3\3.10.5\lib\site-packages\pandas\core\internals\construction.py", line 753, in _get_axes
columns = ensure_index(columns)
File "C:\programs\gttools\python3\3.10.5\lib\site-packages\pandas\core\indexes\base.py", line 7374, in ensure_index
return Index._with_infer(index_like, copy=copy, tupleize_cols=False)
File "C:\programs\gttools\python3\3.10.5\lib\site-packages\pandas\core\indexes\base.py", line 715, in _with_infer
with warnings.catch_warnings():
File "C:\programs\gttools\python3\3.10.5\lib\warnings.py", line 446, in __init__
self._module = sys.modules['warnings'] if module is None else module
Debug info
Streamlit version: 1.15.2
Python version: 3.10.5
Using Conda? PipEnv? PyEnv? Pex? No. Working locally with Python installations and site-packages.
OS version: Windows 10, Version 21H2
Browser version: Edge Version 107
Requirements file
No, working locally with everything already installed.
Can you insert the version checks right after the import lines and see if it can execute that? If so, what versions did you get? If not, can you try a new environment or maybe try reinstalling the modules?
Yeah, seems like something. Looks like Streamlit is running fine with the simple write version commands and youâve got the same combo as one of the environments I used. Can you spin up a clean environment to try? Or since the errors seem to be in pandas, you might try reinstalling that module.
((Are you familiar with using environments to make it easy to play around with different module versions? Iâm on my tablet, but can pop over to desktop to grab a few easy directions. Do you just have Python installed directly? Do you have Anaconda? I like Anaconda for easy environment management.))
Yes, I know my way around environments. So, let me start anew; maybe something happened after I installed one too many web frameworksâŚI have been reading up online and experimenting with flet, flask, nicegui, web2py, streamlitâŚlooking for the one I would like.
Were you able to run the code in a clean environment?
As for which is best, I think it highly depends on your use case/skills. One of Streamlitâs strong points is that you get to an operable dashboard with very little code and that itâs probably one of the most beginner friendly options.
However, if your goal is a broader, more generic web framework, youâll probably feel constrained in Streamlit.
This web stuff is all new to me, but, apparently, the direction new management wants to go; so, here I am.
I am an engineer and work for an engineering department, but moved to the software side of things some years ago. Given that the know-how is proprietary and very technical, most in-house software is written by engineers with little software knowledge and even less interest in developing such skillâŚthis is one reason why I typically prefer/search easy-to-use options.
So, I started with a clean Python installation and âonlyâ installed streamlitâŚthe example now works.