Strange Line Chart for Temperature

Hi I’m new to pandas and also streamlit.

i just want to build an easy streamlit page which shows some values about the temperature in the fridge and the freezer. This works fine, but if i try to visualize it with the line chart its just strange. Data source is a mongoDB hostet at Atlas Cloud.

If i print my test data in the console it looks like:

then i’ve written the following code:

try:
    # get Client
    client = init_connection()
    # connect to DB
    mydb = client["brk-regenstauf"]
    # get collection
    mycol = mydb["coolingreporting"]

    # get all data from collection
    freezer = mycol.find({"type": "freezer"})
    fridge = mycol.find({"type": "fridge"})
    col = mycol.find({})
    # convert to pandas dataframe
    p_freezer = pd.DataFrame(freezer)
    p_fridge = pd.DataFrame(fridge)
    df = pd.DataFrame(col)
    # print data
    print("freezer")
    print(p_freezer)
    print("fridge")
    print(p_fridge)

except Exception as e:
    st.write(e)

st.line_chart(df.get(["time", "temperature"]))

chart_data = pd.DataFrame(
    df.get("time"),
    df.get("temperature"),
    columns=df.get("type"))

st.line_chart(chart_data)

st.line_chart(x=df.get("time"), y=df.get("temperature"))

The first Chart which i’ve tried looks wrong as you see here:

Then i’ve tried to following the docs of Streamlit for the line Chart and nothing shows up or an error occurs …


2022-08-28 11:52:54.794 Uncaught app exception

Traceback (most recent call last):

  File "/home/appuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 556, in _run_script

    exec(code, module.__dict__)

  File "/app/cooling_report/cooling_report.py", line 80, in <module>

    st.line_chart(x=df.get("time"), y=df.get("temperature"))

  File "/home/appuser/venv/lib/python3.9/site-packages/streamlit/elements/dataframe_selector.py", line 198, in line_chart

    return self.dg._arrow_line_chart(

  File "/home/appuser/venv/lib/python3.9/site-packages/streamlit/elements/arrow_altair.py", line 130, in _arrow_line_chart

    chart = _generate_chart(ChartType.LINE, data, x, y, width, height)

  File "/home/appuser/venv/lib/python3.9/site-packages/streamlit/elements/arrow_altair.py", line 486, in _generate_chart

    data, x_column, x_title, y_column, y_title, color_column, color_title = _maybe_melt(

  File "/home/appuser/venv/lib/python3.9/site-packages/streamlit/elements/arrow_altair.py", line 404, in _maybe_melt

    if x and isinstance(x, str):

  File "/home/appuser/venv/lib/python3.9/site-packages/pandas/core/generic.py", line 1527, in __nonzero__

    raise ValueError(

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

2022-08-28 11:54:01.738 Uncaught app exception

Traceback (most recent call last):

  File "/home/appuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 556, in _run_script

    exec(code, module.__dict__)

  File "/app/cooling_report/cooling_report.py", line 80, in <module>

    st.line_chart(x=df.get("time"), y=df.get("temperature"))

  File "/home/appuser/venv/lib/python3.9/site-packages/streamlit/elements/dataframe_selector.py", line 198, in line_chart

    return self.dg._arrow_line_chart(

  File "/home/appuser/venv/lib/python3.9/site-packages/streamlit/elements/arrow_altair.py", line 130, in _arrow_line_chart

    chart = _generate_chart(ChartType.LINE, data, x, y, width, height)

  File "/home/appuser/venv/lib/python3.9/site-packages/streamlit/elements/arrow_altair.py", line 486, in _generate_chart

    data, x_column, x_title, y_column, y_title, color_column, color_title = _maybe_melt(

  File "/home/appuser/venv/lib/python3.9/site-packages/streamlit/elements/arrow_altair.py", line 404, in _maybe_melt

    if x and isinstance(x, str):

  File "/home/appuser/venv/lib/python3.9/site-packages/pandas/core/generic.py", line 1527, in __nonzero__

    raise ValueError(

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

I’m lost now … Does anybody has an ideal what my mistake can be? Need some other eyes and brains on that.

Thank you!
Regards
Florian