I’ve been struggling to figure out how to resolve this issue and have tried everything I can think of and can’t figure out how to resolve it.
Basically, whenever a float value has a leading 0.0 all leading 0s are being removed before the dataframe is rendered in streamlit.
Here is a screenshot of what shows in streamlit:
Here is a screenshot of the df in my IDE before it is added to streamlit:
You can see the “Executive & Admin” value is 0.091400 but in the streamlit UI it shows it as 91400.
If there are more leading 0s like 0.0000100 it would just show as 100. No idea why and not sure what to do to fix it?
It works totally fine if I manually create a data frame and type in 0.00123, but if the data comes from a query from st.experimental_connection, it doesn’t seem to work
Using the snowpark connection. I’ve tried both the direct result from the snowpark connection.query(sql) as well as taking that result and attempting to convert it to a pandas dataframe (even though I’m pretty sure that query returns a pandas dataframe).
I have a feeling if you connect to snowflake via snowpark and do something as simple as select 0.000123 as f and put those results into the table, it wouldn’t render correctly, but haven’t tried it yet…
@CarlosSerrano is there any way to do this generically? Ideally a solution that formats float columns as float, but non-float columns as ints and strings? I guess I could look at the data to do this, but was hoping for a “simpler” solution.
@CarlosSerrano I ran into this issue again, not exactly the same, but very similar…
Code and screenshot below
sql = """
WITH NumberSequence AS (
SELECT
ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) r,
ROUND(UNIFORM(3200000, 3300000, RANDOM())) AS num
FROM
TABLE(GENERATOR(ROWCOUNT => 12))
), t1 as (
select * from NumberSequence
), t2 as (
select * from NumberSequence
)
select
t1.*,
t2.num + 200000 as num2,
ROUND(((t1.num - num2) / t2.num) * 100, 1) AS percentage_change
from t1
left join t2 on t2.r = t1.r
"""
df = conn.query(sql)
st.dataframe(df, hide_index=True)
Unfortunately the sql is being generated by gpt… Any other ideas for streamlit to interpret the data format better? Python prints the dataframe fine… And ironically the df export to csv from the streamlit download button is also correct, so it’s just the displayed table that is incorrect
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.