Converting a dataframe to have dropdown values to update similar to data validation in excel


I am trying to build a streamlit app that connects to a snowflake table, fetches data and displays as editable table in streamlit and writes back the edited info back to snowflake, I am able to get this until here. However, I want to display couple of columns to show as drop down to show values in those columns. Table that I intend to bring is a mapping table and last two columns needs to be provide all the column values as drop down

I want file name and column name as dropdowns for selection in the dataframe and i will be writing this dataframe into snowflake finally

Hi ! hope this helps out !

import streamlit as st
import pandas as pd
from io import BytesIO

df=pd.DataFrame({'Num_col': [1000, 2000, 3000], 'Comma_col': [4000, 5000, 6000], 'PC_col': [18, 83, 64]})

flnme = st.text_input('Enter Excel file name (e.g. email_data.xlsx)')
if flnme != "":
    if flnme.endswith(".xlsx") == False:  # add file extension if it is forgotten
        flnme = flnme + ".xlsx"

    buffer = BytesIO()
    with pd.ExcelWriter(buffer, engine='xlsxwriter') as writer:
        df.to_excel(writer, sheet_name='Report')

    st.download_button(label="Download Excel workbook", data=buffer.getvalue(), file_name=flnme, mime="application/")

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.