I am working on a Data Profiling project.
I want to change the background color of empty white spaces in options of the multiselect widget.
When the user chooses a certain option from a radio widget, the code gets the unique values of a pandas column and shows them in a multiselect widget.
I want the change the background color of the spaces because sometimes the same values have leading/trailing white spaces, and I want the user to be able to see them in order to choose the values without the trailing/leading whitespaces.
Example of what I need:
Is that, or any other approach to handle leading/trailing whitespaces, achievable in any way?
yes actually, I want to show the quality of the data in columns.
So in case of categorical data, a list of the values existing in the column must be shown, in order to choose the correct values that we want to compare the column’s values against.
In the example above, we would select “Value A” and “Value B” that are without the trailing/leading spaces (as the only values that should exist in this column). Then the algorithm would check this rule, and get back with the rate of correct values against wrong ones.
Th wrong ones are the values with spaces, or are different values than the chosen.
If the solution as in the above photo is not possible, then maybe changing the color of the values with the spaces to red? Is that possible?
I think I’m understanding, but I might be conceptualizing something different. From your explanation, I would construct something like:
Get all unique values in a column
Display the list in html where it’s much easier to format the display. This would give a clear picture of what exists.
Provide a selection of trimmed values for the user to select
Can also check if trimming some element results in a new element not originally seen
Is there a reason you want to provide them the option of selecting a “wrong” choice?
(Off the top of my head, I don’t know how to format individual options in the a selection widget like that. It might be possible, but probably a little messy. I will play around.)
One option, though it’s not a general-purpose solution to formatting:
def formatter (x):
try:
return str(x).replace(' ','⬛')
except:
return x
with st.form('my_form'):
st.selectbox('Choose',[' This is an option','This is an option','This is an option ', 'This is an option '], index=0, format_func=formatter)
st.form_submit_button('submit')
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.