Hello - new to streamlit here so forgive me but I keep running into this issue. I am trying to use the multiselect function to filter an st.metric block. The dataset is a simple excel spreadsheet of income earned by day, with a Y/N column to represent if that daysâ worth of work has been paid yet or not.
Year = st.multiselect(
âSelect the Year:â,
options=df[âYearâ].unique(),
default=df[âYearâ].unique()
)
Month = st.multiselect(
âSelect the Month:â,
options=df[âMonth_Yearâ].unique(),
default=df[âMonth_Yearâ].unique()
)
Paid = st.multiselect(
âSelect Paid?:â,
options=df[âPaidâ].unique(),
default=df[âPaidâ].unique()
)
df_selection = df.query(
âYear == @ Year & Month == @ Month & Paid == @ Paidâ
)
#in the actual code, there are no spaces but streamlit thinks I am trying to tag people
left_column, middle_column, right_column = st.columns(3)
with left_column:
revenue_total = df_selection[âMoneyâ].sum()
st.metric(label=âTotal Revenueâ, value= â%.2fâ % revenue_total)
with middle_column:
paid_total = df_selection.loc[df[âPaidâ] == âYâ].Money.sum()
st.metric(label=âPaidâ, value= â%.2fâ % paid_total)
with right_column:
not_paid_total = df_selection.loc[df[âPaidâ] == âNâ].Money.sum()
st.metric(label=âNot Paidâ, value= â%.2fâ % not_paid_total)
When ran, I am receiving the following error message:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
I believe the df_query function is having trouble taking in all the unique instances of the filters, but I pulled the code directly from this youtube tutorial: Turn An Excel Sheet Into An Interactive Dashboard Using Python (Streamlit) - YouTube
Any suggestions help. Thank you!