In this article, we’ll guide you through building a fun Streamlit app that displays tennis statistics. Streamlit is an open-source framework that allows you to create beautiful, interactive web applications in Python with just a few lines of code. For this project, we’ll use a tennis player rankings dataset and visualise the data with easy-to-understand charts. We wanted to have fun with this project, so we chose tennis statistics as an example.
What You Need to Get Started
Before we dive into building the app, here’s a list of what we’ll be working with:
- Python Environment: Make sure you have Python installed. I recommend setting up a virtual environment to manage your dependencies more effectively.
- Streamlit: The core library we’ll use to build the app and display interactive visualizations in a web interface.
- Pandas: This library helps us manage and manipulate the ATP dataset for analysis and visualization.
- Plotly: We’ll use this for creating interactive and visually appealing charts.
- Dataset: The dataset (rank_atp.csv) contains information about ATP tennis players, such as their ranks, nationality, age, and other statistics.
- ranking.py: A script that automates the process of collecting real-time ATP rankings data, which is updated regularly.
- Railway: The platform we use to deploy and automate the execution of the script, ensuring that the data is always up-to-date.
Files You’ll Work With
Here’s a quick breakdown of the files included in this project:
- main.py: This is the main Python file where the app’s logic lives. It loads the dataset, creates interactive charts, and displays them using Streamlit.
- rank_atp.csv: The CSV file contains the data for ATP tennis players, including player ranks, countries, and ages.
- requirements.txt: This file lists all the required Python libraries, including Streamlit, Pandas, and Plotly, so you can easily set up the environment.
What the App Does
Once you run the app, it will display interactive visualizations that allow you to easily explore and analyze ATP rankings data. Some of the key visualizations in the app include:
- Bar Chart: This chart shows the top countries based on the number of players in the ATP rankings. This gives a quick visual indication of which countries dominate the sport.
- Histogram: This chart visualizes the distribution of players’ ages, allowing users to see the age range of top-ranked players.
- Box Plot: This is used to show the distribution of ages in top countries, including the median, quartiles, and potential outliers.
- Pie Chart: Displays the number of players from each continent, giving an easy-to-understand breakdown of where players are coming from.
- Bar Chart: Represents the number of players per million population by country, providing a clearer perspective on which nations are producing ATP players at the highest rates.
- Stacked Bar Chart: A comparison of top countries in each continent based on the number of players ranked in the ATP.
The data updates regularly, giving you a current snapshot of the ATP rankings, and the interactive charts make it easy to explore the data in various ways.
Key Visualizations in the App
Here’s a detailed overview of the visualizations you’ll find in the app, which allow you to explore different aspects of the ATP rankings and player demographics:
- Age Distribution Analysis:
- Age Statistics (min, max, mean, median, quartiles, and standard deviation) give insights into the age range of top-ranked players.
- Bar Chart: Displays the age distribution of players.
- Box Plot: Visualizes the spread and central tendency of ages, allowing you to see where most players fall in terms of age.
- Players per Million Population:
- This visualization breaks down how many ATP players exist per million people in each country. This helps understand which countries are producing the most top-tier tennis talent relative to their population size.
- Pie Chart: Distribution of ATP players by continent, showing how the sport is spread geographically across the world.
- Bar Chart: Shows the number of players from each country as a proportion of their population.
- Country Breakdown by Population:
- A breakdown of players from each country relative to their population, showing the countries that produce the highest number of ATP players.
- Bar Chart: Displaying the number of players per country, alongside population sizes to give a better context.
- Player Distribution by Continent:
- Visualizes the number of players from each continent, helping to identify regions that have the most representation in the ATP rankings.
- Pie Chart: Shows the percentage of players from different continents such as Europe, North America, South America, and Oceania.
- Top Countries per Continent:
- Identifies the leading countries in each continent based on the number of ATP players they have.
- Bar Chart: Highlights the countries that are leading in each continent in terms of ATP players. For example, Italy might be leading Europe, while the USA leads North America.
- Age Distribution by Top Countries:
- Visualizes the age distribution for players from top countries, providing a deeper look into how age demographics vary across regions.
- Bar Chart: Shows the count of players in top countries, along with the minimum, maximum, mean, and median ages for each country.
- Nationality Breakdown:
- Pie Chart: A breakdown of players’ nationalities, helping to easily identify the countries with the most ATP players represented in the rankings.
- Top Countries in ATP Rankings:
- Displays the countries with the most top-ranked players, allowing users to quickly identify the strongest tennis nations.
How the Data Is Collected and Updated
To ensure the data remains current, the app uses a ranking.py script that collects new data every week. This script pulls the latest ATP rankings, updates the dataset, and ensures the visualizations reflect the most recent player information. Initially, this was automated using GitHub Actions, but due to issues with Chrome versions in the CI/CD pipeline, we switched to Railway, a platform that provides more stability and ease of use for this purpose.
Railway automates the collection and processing of ATP rankings data, keeping the app’s information up-to-date without requiring manual intervention. The app is deployed on Railway, ensuring that the ranking updates occur automatically without worrying about maintenance.
Conclusion
This app serves as an easy-to-use, interactive tool for exploring the ATP rankings, player demographics, and trends in tennis. It visualizes important aspects such as player distribution by continent, country, and age, and makes the data more accessible and engaging. With the automatic weekly data updates powered by Railway, you’ll always have the latest ATP rankings right at your fingertips.
By leveraging tools like Streamlit, Pandas, and Plotly, the app provides clear insights into the sport of tennis without requiring advanced data analysis skills. Whether you’re a tennis fan, researcher, or just curious about the current state of the ATP rankings, this app offers a dynamic and interactive way to explore the data.
You can find the complete code here.

Alex is an experienced SEO consultant with over 14 years of working with global brands like Montblanc, Ricoh, Rogue, Gropius Bau and Spartoo. With a focus on data-driven strategies, Alex helps businesses grow their online presence and optimise SEO efforts.
After working in-house as Head of SEO at Spreadshirt, he now works independently, supporting clients globally with a focus on digital transformation through SEO.
He holds an MBA and has completed a Data Science certification, bringing strong analytical skills to SEO. With experience in web development and Scrum methodologies, they excel at collaborating with cross-functional teams to implement scalable digital strategies.
Outside work, he loves sport: running, tennis and swimming in particular!