Hi Everyone,
Hope you guys are doing fine,
I’m trying to create a new data frame from the existing one with one new column of values, when I try to set a value to the cell or append new values to a list, the old values are getting deleted,
I don’t know why is this happening, is it due to the session state or some other thing.
TIA
import streamlit as st
import pandas as pd
if 'cc' not in st.session_state:
st.session_state.cc = 0
def increment_counter():
print('product', st.session_state.cc)
st.session_state.cc += 1
data_li = []
df = pd.read_csv("demo.csv", usecols=['productId','productName'])
df = pd.DataFrame(df, columns=['productId','productName', 'Comments'])
col1, col2 = st.columns([5, 5])
with col1:
st.dataframe(df)
with col2:
with st.form("my_form"):
if st.session_state.cc < len(df):
pid = df["productId"][st.session_state.cc]
pname = df["productName"][st.session_state.cc]
comm = st.text_input("Comments :", value='Good')
else:
st.error("reached end of the file")
data_li.append([pid, pname, comm])
st.dataframe(data_li)
approved = st.form_submit_button("Next", on_click=increment_counter())
if approved:
data_li = data_li.append([pid, pname, comm])
st.dataframe(data_li)
st.dataframe(df)
st.dataframe(data_li)