Plot a bar chart using groupby function and plotly and streamlit

i am trying to plot a bar chart based on groupby function but once i try it crash and display the below error:

this error below appear when the user select 3 items from the multiselect widget.

ValueError: All arguments should have the same length. The length of argument color is 3, whereas the length of previously-processed arguments [‘gender’, ‘count’] is 95

code:

some_columns_df = df.loc[:,['gender','country','city','hoby','company','status']]
some_collumns = some_columns_df.columns.tolist()

select_box_var= st.selectbox("Choose X Column",some_collumns)
multiselect_var= st.multiselect("Select Columns To GroupBy",some_collumns)  

test_g3 = df.groupby([select_box_var] + multiselect_var).size().reset_index(name='count')
fig = px.histogram(test_g3,x=select_box_var, y='count',color=multiselect_var ,barmode = 'group',text_auto = True)

            

I know the error is in the color parameter in the px.histogram

If I’m not mistaken, the function is expecting an entire series, where each distinct value in the series will get its own color. So instead of multiselect_var, you need to pick whatever the column name in test_g3 is, or make that available within the group_by statement that creates that dataframe.

Best,
Randy

I did not understand your answer i tried to use test_g3 for color it crash and display the below error: the truth value of a Dataframe is ambiguous. Use empty,a.bool(),a.item(),a.any(),or a.all()