How to create double side slider with DataFrame

Im trying to have double slider but it wont work if i pass dataframe:


    with col4:
        minMiles = df["Miles"].min()
        maxMiles = df["Miles"].max()

        mylios = st.slider('Miles', value=[0, 5000])

gets me error : ValueError: operands could not be broadcast together with shapes (676,) (2,)
wich leads to my filter of things :
df = df[(df[“Date”] >= date1) & (df[“Date”] <= date2) & (df[“Weight”] <= svoris) & (df[“Miles”] <= mylios)].copy()
^^^^^^^^^^^^^^^^^^^^^

Miles in my column varies but most of them have .00 values like 652.7 or 564.77 etc.
If i change value to minMiles and maxMiles im gettin the same error.

I tried different approach:

        minMiles = df["Miles"].min()
        maxMiles = df["Miles"].max()
        minMiles, maxMiles = st.select_slider('Select Range',
            options=['0', '5000'],
            value=(minMiles, maxMiles)
        )
        # mylios = st.slider('Miles', value=[minMiles, maxMiles])
    df = df[(df["PDate"] >= date1) & (df["PDate"] <= date2) & (df["Weight"] <= svoris) & (df["Miles"] <= minMiles, maxMiles)].copy()

getting this error:
ValueError: 139.1 is not in iterable
minMiles, maxMiles = st.select_slider(‘Select Range’,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

How do i need to deal with ? only one way slider works, but imlooking for double sided so i can choose my trip beteween the ranges i want and not from 0 to what ever i choose.

I also tried from Streamlit Youtube video Streamlit Double Sliders same outcome as the first one.
My Miles column is float64.

Hi @BSDevo

Thanks for your question!

Would something like this work:

import streamlit as st
import pandas as pd

df = pd.read_csv('your_data.csv')

minMiles = df["Miles"].min()
maxMiles = df["Miles"].max()

mylios = st.slider('Miles', min_value=minMiles, max_value=maxMiles, value=[minMiles, maxMiles])

df_filtered = df[(df["Date"] >= date1) & (df["Date"] <= date2) & (df["Weight"] <= svoris) & (df["Miles"] >= mylios[0]) & (df["Miles"] <= mylios[1])].copy()
st.write(df_filtered)

Best,
Charly

1 Like

Worked like a charm.
Thank You Sir !
And i see where i made my mistakes and how to solve it.

Glad it helps! :hugs:

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