Python Data Visualization Transcripts
Chapter: Streamlit
Lecture: User input

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Now let's go back to our code and actually do something with the user inputs. So you'll notice that the multi select,
0:08 it returns a make variable and the slider returns a year range. We want to use that to filter our data.
0:17 So the first two filters we're going to do is once we get the year range which is returned as a tuple will get the start and the end range and make
0:30 sure that our data is filtered between those two ranges. And then we'll also make sure that the make is within that make list that is
0:39 returned from the multi select. So now what I'm gonna do is create a new data frame that is filtered based on those inputs.
0:51 So we'll call this the plot data frame and it's saying take the original data frame
0:56 and apply the make filter and the year filter based on these inputs. I'm going to do one other quick update so you can kind of see how this
1:07 works. So what I'm gonna do now is I'm going to calculate the average fuel economy for this new data frame.
1:17 I'm gonna calculate that average around it and then I'm going to use the metric function
1:22 to show that value and this will give you a idea of how to do interactivity So now we have our new file let's go back and we see that the
1:34 source file has changed. So now we can rerun and you see this average getting displayed. So now as I change things,
1:43 the average gets updated based on my selections. So we can change the year range, we can add a lot more.
1:54 Maybe add a cadillac here and the range is updated. And so what's really interesting about this is all this is happening behind the scenes.
2:04 Somehow streamlit knows that there has been a change to our widgets that the user has
2:11 supplied a new value and then it runs this code all behind the scenes. That's one of the things that is really nice about Streamlit is it takes very
2:19 little additional code to give that interactivity to your users using all the kind of existing
2:27 data frame infrastructure and pandas infrastructure that you've built.


Talk Python's Mastodon Michael Kennedy's Mastodon