Instead of uploading a csv file, i want to create one form which will be converted into dataframe⊠i want that form to have drop down list for each row. once the user fills the information by using the drop down list, he should be able to add new row⊠I tried multiple ways but its not working⊠the closest I got is as belowâŠ
when iâm clicking on add row, the app is refreshing and the earlier updated field is being removedâŠ
I tried session state also but iâm getting errors.
Bellow is my code with session option
import streamlit as st
import pandas as pd
# Define column names for the empty dataframe
columns = [âPerson_nameâ, âLocationâ, âAAAAâ, âBBBBâ, âCCCCâ, âDDDDâ, âEEEEâ, âFFFFâ]
# Create an empty dataframe with the defined columns
empty_df = pd.DataFrame(columns=columns)
# Define a list of people to choose from
people = [âJohnâ, âMaryâ, âJaneâ, âMarkâ, âLucyâ]
# Create an empty session state variable
session_state = st.session_state
# Check if the session state variable is already defined
if âdfâ not in session_state:
# Assign the initial data to the session state variable
session_state.df = empty_df
session_state.row = pd.Series(index=columns)
# Create a selectbox for each column in the current row
for col in columns:
# Get unique values from the corresponding column in the resource_data dataframe
if col == âPerson_nameâ:
values = people
else:
values = [âYâ, âNâ]
# Create a selectbox for the current column and add the selected value to the current row
session_state.row[col] = st.selectbox(col, values, key=col, index=values.index(session_state.row[col]))
# Add a button to add a new empty row to the dataframe and clear the values of the selectboxes for the current row
if st.button(âAdd Rowâ):
session_state.df = session_state.df.append(session_state.row, ignore_index=True)
session_state.row = pd.Series(index=columns)
# Display the resulting dataframe
st.dataframe(session_state.df)
Please somebody help me out