I have tried a combination of conditions with the OR | operator and not getting the desired result. This code didnt work.
df.query("(Subgenre == @subgenre & YEAR == @year & Country == @country) | (Subgenre == @subgenre & YEAR == @year) | (Subgenre == @subgenre & Country == @country)")
I want for the list to generate whether 2 or 3 of the conditions are met.
Here is my code
import pandas as pd
import streamlit as st
st.set_page_config(page_title="Horror Movie List",
page_icon=":bar_chart:",
layout='wide')
df = pd.read_excel(
io='list.xlsx',
engine= 'openpyxl',
sheet_name='Movies',
usecols='A,C,D,E,F,G,J,L,M,N,O,P,Q',
nrows=1000,
).fillna('')
# SIDEBAR
st.sidebar.header("Please Filter Here")
subgenre = st.sidebar.multiselect(
"Subgenre",
options=df["Subgenre"].unique()
)
year = st.sidebar.multiselect(
"Year",
options=df["YEAR"].unique()
)
country = st.sidebar.multiselect(
"Country",
options=df["Country"].unique()
)
df_selection = df.query(
'Subgenre == @subgenre & YEAR == @year & Country == @country'
)
st.dataframe(df_selection)
Also under 'Country', I want to default select 'USA' ('USA' is a row in a column labeled "Country') but this code below doesn't work.
country = st.sidebar.multiselect(
"Country",
options=df["Country"].unique(),
default=df.loc[('Country','USA')]
)
Thank you!