Df_query for updating st.metrics

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!

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.