The world’s leading publication for data science, AI, and ML professionals.

Building an Application with Survey Data on Streamlit

For the last couple of months I have been playing around with Streamlit as it is an awesome way of producing data science web applications with just one Python script.

The beauty of the technology is that it removes the requirements of having to programme the front end technology leaving you to focus on the good stuff – telling an engaging data story.

I work with a lot of survey information and I thought it would be interesting to build an application with the data we collected from a ski based survey.

There were a couple of reasons for my motivation to produce this app with Streamlit:

  • Shareability – Getting the app into production is super easy, it will sit on the Streamlit cloud and you are provided with a unique url that you are able to share which makes it very accessible. It is also mobile-first which is great for cross-device compatibility.
  • Interactivity – I wanted my brand partners and colleagues to be able to interact and engage with the app to provide more value in the insights by adjusting the input parameters to produce different results.

This article will cover how the app was built at a high-level, there are plenty of other excellent articles on the intricacies of Streamlit.

Data Cleansing

Survey data can often be very messy when it comes out the other end – this is because the question and answer format of a survey does not often translate into a clean formatted data set. Having said this, over time I have used my experience to adjust the question structure of the surveys to make the data formatting process more efficient.

The first port of call was to get the data into a Jupyter Notebook so that Pandas could be used to format the dataframe into something that I could then run my analysis on.

From here I dropped the rows that contained survey question information so that I was left with the users’ data and formatted the columns so that they were easy to work with – shortened the name, lowercase, no spaces etc.

Data Engineering

Once I had the information where I wanted it to be I ran some data visualisations to get a better understanding of the data which allowed me to start building my story.

I wanted to display the brands our audience had bought into based on the number of times they ski a year and their preferred style of skiing.

To test this, I built a function in the notebook and then called the function to review the output.

Streamlit Python Script

Once I had an understanding of how the app was going to run from an engineering point of view I started to build the app in a .py file.

As mentioned, interactivity was really important for this project and I wanted the user of the app to be able to select the input data which would then feed directly into the core function of the script that would then produce the output data and the key visualisation.

I used Streamlit’s selectbox which saved the selected data as a variable which then fed into the core function and produced the barplot.

Conclusion

Streamlit coupled with my data analysis skills in Python allowed me to create an interactive web-application that turned pedestrian survey data into a tool that allows users with zero Analytics skills to extract a huge amount of value. I am excited to see how the technology progresses and I will continue to explore what can be created with Streamlit.

If you would like to find out more about this project please connect with me on LinkedIn and I will be happy to pick up the conversation, the source code for the project is also available on my GitHub.


Related Articles