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