St.line_chart doesn't display the correct data

Hi, streamlit newbie here, I’m having trouble having my first app displaying anything with a line_chart. I’m using streamlit in Snowflake. Here’s my use case:

  1. read some data from a Snowflake table (looks ok)
  2. extract relevant columns from the results returned from the select (a timestamp and a numerical column (also looks ok)
  3. plot numerical values vs timestamp

the final step either shows nothing, some axis labels with no data, or (if I include just the numerical data, no timestamps), values totally unrelated to the data in the table.

Code looks like this:


# Get current session
session = get_active_session()

def load_data():
    # Load and transform daily stock price data.
    # football_prices = (
    # )
    query=f"select * from <snowflake table name> limit 20"
    data = pd.DataFrame(session.sql(query).collect())
    return data

fdata = load_data()

chart_data = pd.DataFrame(fdata, columns=["PRICE"])
st.line_chart(chart_data, y="PRICE", use_container_width=True)

the above code produces the results where the numbers are nothing like the data!
I’m expecting a range between 0.0 and 400.0, I’m getting values like those shown in the clip shown below
Any suggestions to what is going on and what I can change?


I wonder if it’s because pandas is not sure how to correctly interpret the data in the PRICE column – I think there are sometimes issues between snowflake and pandas when the data is in DECIMAL type. Can you try casting the data in your query, like

select price::float as price, date from <table name>

And see if that helps resolve the issue?

You’ll probably also need to pass x="DATE" (or whatever the date is called) to st.line_chart

Thanks for the quick reply @blackary. yes, casting the field at select time helped, but what if I’m running a select * from - how would I choose my columns from the dataframe that’s returned. Likewise I assume I have to do something to the timestamps returned to make them streamlist friendly - any suggestions for how to do that?

Or, to put it another way - when I get the results of my select * from Snowflake, how do I cast the entire column of the dataframe to be all float, or all a valid format of timestamp?

Sorry, I don’t know a way to cast multiple columns at once that way without just using their names.