I looked on the web and some parts of the documentation but couldn’t be able to find a proper answer. So I decided to ask here, if this is irrelevant, please feel free to delete the post.
I am trying to build an A/B testing tool which creates academic tables for manuscripts as well. The tool will get a data file in .csv, .xlsx and .sav formats. However, as you all may know, the data types of the columns would not be proper for statistical analysis as they are in object type or something similar.
My first idea was to create a change_columns function, check if all the rows of the column are only numeric or strings and then change the types accordingly with pandas. However, It can be really slow and inefficient.
So I thought it would be a good idea if the users can change the data types with dropdown menus. And there comes my question here;
I want the user to choose columns and the app will show its data type
From a dropdown menu (or anything useful) will show desired data types - float16, object/category, int16 (16 is not a must of course)
And depending on the choices that the user made, my function will run df[col] = df[col].astype(selection)
@orkunaran Since you have a fixed set of options to select from, a selectbox seems like a great option to me. But, in general, the best thing to do is just try it and see if it feels right. Streamlit makes iterating on an app super easy, so don’t feel like if you want to change your mind later it will be hard.
For example, it’s easy to change from
x = st.selectbox(options...)
to
x = st.select_slider(options...)
or even
x = st.text_input(...)
And no other part of the script will care what widget you used, it will happily just use whatever the value of x is.
Thank you for the detailed answer. I managed to solve my problem with ease. It seems it was a really basic question. Please excuse me if I wasted your time.
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.