Streamlit: How can I drop multiple columns of a dataframe each time a user input is given?
xcols=st.number_input("Enter a Number")
df.drop(df.columns[xcols],axis=1, inplace = True)
st.write(df)
This code drops 1 column and then if another number is typed, then the deleted column reappears?
I also tried adding it to a list called DeletedColumns=[]
that still didnt work and only deletd 1 column
CodePudding user response:
Drop as an in delete? In this case you can use this:
df.pop["Column Name"]
CodePudding user response:
Since streamlit starts executing the code at the beginning whenever you refresh the page or make an input update on the web, if you're showing a data table from a file and don't remove those columns from that specific file, the data table column will keep reappearing when you repeatedly modify the input. This is because the dataframe you're reading from a file will re-execute and fetch the data. May be that's the issue.
Refer the link for more info: Data Flow in Streamlit