How to show results with multi slider

First of all, I am a beginner with python. I come across the following issue, I am able to show results from my xlsx file when I select the Models, but when I add the multi slider I can’t get any results. But if I use st.write I can get the values. I was wondering how I can get the results after selecting the models and price range. Many thank in advance.

import streamlit as st
import pandas as pd
import base64
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
import time
import requests
import json

st.title('TWS features')

st.subheader('All data')

def load_data():
    df=pd.read_excel("/Mylocation/TWS Data.xlsx")
    twsdata = df
    return twsdata

twsdata = load_data()


# Sidebar = Model Selection
sorted_unique_model = sorted(twsdata.Model.unique())
selected_model = st.sidebar.multiselect('Model', sorted_unique_model, sorted_unique_model)

# Sidebar = Price Range
min_price = int(twsdata['Price'].min())
max_price = int(twsdata['Price'].max())
#sorted_unique_price = sorted(twsdata.Price.unique())
selected_price_range = st.sidebar.slider('Select the price range', 0, 999, (0, 999), 1)
st.write('Range Values', selected_price_range)

# Filtering data
df_selected_model = twsdata[(twsdata.Model.isin(selected_model)) & (twsdata.Price.isin(selected_price_range))]

st.header('Display selected TWS')


I think you are getting 0 results because what you receive from the selected_price_range is a tuple and not a single value.
Therefore, the .isin method you are trying is not what you want.

One possible solution would be to use .between instead of .isin

    df_selected_model = twsdata[(twsdata.Model.isin(selected_model)) & (twsdata.Price.between(selected_price_range[0], selected_price_range[1]))]

Or you could just add the price filters as separate & conditions, however you prefer :slight_smile:

Let me know if this solved your problem.



This works. Thank you @Alex_31 for the tip!

1 Like