Based on the solution from the following link, I have the following code to append user input numbers to a df, and I would like to write a small function to be able to delete last row in case user makes a mistake. The Delete row
button doesn’t work. Appreciate any hint on what I am doing wrong.
import streamlit as st
@st.cache(allow_output_mutation=True)
def get_data():
return []
def drop_last_row(df):
df = df[:-1]
return df
time1 = st.number_input("Elapsedtime 1")
time2 = st.number_input("Elapsedtime 2")
value_mean = st.number_input("Mean value")
if st.button("Add row"):
get_data().append({"Time 1": time1, "Time 2": time2, "Mean Value": value_mean})
if st.button('Delete row'):
df = get_data()
drop_last_row(df)
df = pd.DataFrame(get_data())
st.write(df)