
Motivation
If you follow football at all, you must have heard about fantasy football games at some point. Many football leagues have their own, with their specific rules, and the Premier League is no exception. More than that, the game on that island is very popular, with more than 8M people playing it worldwide. In this article, we will look at how Fantasy Premier League managers can analyse their team using Python.
Although the game does a good job of showing you some insights about your team, it could be a bit more graphic than just numbers on a page. This is where the FPL APIs and a few lines of Python code come in handy to build different kinds of visualisations showing the most important aspects of any manager’s team and their development game week after game week.
Identifying and Getting the Relevant Data
The idea here is to start small, with the essentials (points, rank, team value, transfers, captain choices and points per position). This will already bring a ton of insights about a manager’s team.
In order to get the required data for this project, we will use the FPL APIs. Although there’s no documentation built around them, thanks to a simple network scan of the different FPL web pages using the Google Chrome DevTools, we can find the URL endpoints we need. Then, a request to these specific end points lets you access the data in JSON format which are then very practical to handle in Python.

Here are the 4 end points we use to get the required data:
https://fantasy.premierleague.com/api/bootstrap-static/ Generic info about PL teams, the players and the game week details
https://fantasy.premierleague.com/api/entry/_teamID_/event/_gwNumber_/picks/Detailed info about a given FPL Team and a given game week
https://fantasy.premierleague.com/api/entry/_teamID_/ General info about a given FPL Team
https://fantasy.premierleague.com/api/element-summary/_playerID_/ Detailed info about a specific premier league player
That being said, this is what the data mining section looks like:
On top of this, let’s build a few functions to get the Premier League players’ specific data:
With this in the bag, we are ready to roll!
Organising the Data
Now that we got all the raw data from the FPL APIs, the name of the game is to only keep what we need, tidy things up and organise everything in lists and dictionaries. This will make it way simpler to plot the data on our dashboard.
After having initialised all the lists and dictionaries we want to build, we loop through all the game weeks to fetch the data we need and populate the objects we just defined. We use the append method to add elements to the lists whereas for the dictionaries we add (key, value) pairs straightaway.
Creating the Graphs
Right, now let’s build this thing. With all the data properly arranged in lists and dictionaries, all we need really is matplotlib!
1. Game Week Points and Comparison to Highest and Average scores
Let’s start with the basics. The number of points a team gets every week and a comparison to the highest and average scores of the game week is the first graph to be built. I never got even close to getting the highest game week score but the comparison to the average is quite interesting.

2. Evolution of Rank at Each Game Week
Second, let’s look at the team rank at each game week and the evolution of the overall rank. Thanks to this graph you can monitor the performance of your team game week after game week and the overall trend.

3. Evolution of Team Value at Each Game Week
The "financial" part of FPL is crucial if you don’t want to get left behind at the end of the season. Keeping an eye on your finances is essential and this graph does just that.

4. Number of Transfers and Associated Costs
Now let’s look at how active the manager has been over the season so far. This graph shows the transfers made and their potential associated costs.

5. Captain Payoff
The captain choice is so important in FPL that it can completely change the performance of a team in a given game week. This next graph will show you where your captain blanked and where he overperformed.

6. Points per Position
The last graph on our dashboard shows the points you earned per positions. Thanks to this graph you will get a clear idea about which players brought you the most points and which strategy you followed throughout the season. Could be a good idea to compare it to the top players in the game to see what you could be doing differently!

Conclusion
In the case of my team the dashboard ends up looking like this after 10 game weeks:

The collection of graphs we produced in this project is a good start to analyse an FPL team. However, it goes without saying that many more FPL insights could be derived with all the data we managed to get our hands on. Here I put the focus on visualising the most important ones, with potentially more to come!
If you want to analyse your team, the entire code can be found here: https://github.com/Guigs11/fpl_team_analysis