Hi, I am trying to use the selectbox function in my project with the following workflow :
- get value from sqlite database
- convert a column into a list
- get a value with a selectbox function
- use this value into another “select statement”
The code i wrote works well for the first element of the list, but as soon as I change the value with the dropdown list, I get an error really not explicit. Here is my code :
import streamlit as st import pandas as pd import sqlite3 conn = sqlite3.connect('myDB.db') # Connection / Creation of the DataBase c = conn.cursor() conn.commit() df1 = pd.read_sql_query('select col1, col2 ' 'from "myTable1" , conn) list = df1['col1'].to_list() selection = st.selectbox('Choose value :', list) get_id = df1['col2'].loc[df1['col1'] == selection] df2 = pd.read_sql_query('SELECT * FROM myTable2 WHERE ID = ' + str(get_id ), conn) st.dataframe(data=df2)
And the error I get is simply
It says the error is at this level : get_id = df1[‘col2’].loc[df1[‘col1’] == selection] but to my mind this is good because it runs well with the first element of the list and as I said : I only have the error when I change the value of the selectbox.
Thank you for your help!