I’m building an app that imports a csv file containing multiple numeric columns, and the goal once the csv file is imported, is to be able to apply conversion factors to one or more columns. The layout of the app is like this :
Basically, I would like to be able to click on the “apply conversion” button and allow the older conversions to remain. I’m aware I need to manipulate session_state in order to make it, but I’m not sure how.
You can try creating a dictionary in Session State with all of your conversion factors.
import streamlit as st
if "factors" not in st.session_state:
st.session_state.factors = {}
columns = st.multiselect("Columns", options=["A","B","C","D"])
factor = st.number_input("Factor", min_value=0)
if st.button("Apply"):
for col in columns:
st.session_state.factors[col] = factor
st.write(st.session_state.factors)
# Apply the saved factors
This snippet replaces the factor for a column if it was previously set, but you could add a few more lines to check if a column already has a factor saved and compound them instead of replace them, if you want.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.