Values not getting stored into list / dataframe

Hi Everyone,
Hope you guys are doing fine, :heart: :black_heart:

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.

import streamlit as st
import pandas as pd

if 'cc' not in st.session_state: = 0

def increment_counter():
    print('product', += 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:

with col2:
    with st.form("my_form"):
        if < len(df):
            pid = df["productId"][]
            pname = df["productName"][]
            comm = st.text_input("Comments :", value='Good')
            st.error("reached end of the file")

        data_li.append([pid, pname, comm])

        approved = st.form_submit_button("Next", on_click=increment_counter())

        if approved:
            data_li = data_li.append([pid, pname, comm])



Please take a look at the approved button, as the you created change values above and below it.

        approved = st.form_submit_button("Next", on_click=increment_counter())

Every time you press the approved button you are appending to the empty “data_li”, so if you would like to continue appending cell1,cell2… then you should put your data_li as a session state.

if 'data_li' not in st.session_state:

and then append it accordingly.

1 Like

Thanks @cualr , I’ll try this

Thanks, @cualr :sparkling_heart: Working as expected.

1 Like