Circling back to something I have been toying with for far too long. I am using a double slider, but its only displaying data in a DF from the start and end year of the slider, and for some reason it is not including the range between the years. My data frame has 49 years of data, and I am setting the value to a 5 year span to start with, only I expected to see all data within a range when I update the slider, not just the start and end years.
I am pretty sure its the pandas arg of isin that I need to change.
Thoughts on what i am overlooking?
select_office = sorted(df['Office'].unique())
select_office_dropdown = st.sidebar.multiselect('Select one or multiple office(s) to display data:', select_office)
select_year_range = sorted(df['Year'].unique())
select_year_slider = st.sidebar.select_slider('Use slider to display year range:', options=select_year_range, value=(2022,2017))
selected_office_year = df[(df.Office.isin(select_office_dropdown)) & (df.Year.isin(select_year_slider))]
st.map(selected_office_year)
st.dataframe(selected_office_year.reset_index(drop=True))
Hi @andthisjustin , did you try modifying the latter part of the line âselected_office_yearâŠâ to
(df.Year >= year1 & df.Year <= year2), where year1 & year2 will need to be changed to select_year_slider(0) & select_year_slider(1) respectively?
Hi @andthisjustin , sorry I didnât have my laptop last time and therefore, couldnât test the code.
You can reproduce the code and the data at your end to confirm that it is working, before suitably re-purposing it for your use. Change the data file path (i.e. vpth) too as required.
The dataset:
The code:
import streamlit as st
import pandas as pd
vpth = âD:/ShawnP/Pending/Automation/Python/adhoc tst prgs/â
vfl = âmyfile.csvâ
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking âAccept allâ, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.