FPL data guide! đź§µ

First part of a series on how to use #RStats to download and analyse #FPL data!

First things first, downloading the FPL player database, and saving it to a spreadsheet
(1/10)

First up is getting our tools downloaded. I promise this won’t be a pain, and opens up the option to do so much with the FPL datasets.

We’re gonna be using R within the RStudio IDE (interface)
(2/10)

Luckily, the RStudio page covers all the steps to download and install R & RStudio on your platform: https://posit.co/download/rstudio-desktop/
(3/10)
RStudio Desktop - Posit

Posit
Once that’s all installed, open up RStudio and you’ll see something like this. If you don’t see the top left section, then go to file > new file > R script (or CTRL+SHIFT+N).
(4/10)

The red window is our scripts, this is where you can type a bunch of code, and save files. Here, you press CTRL+ENTER to run either the current line, or highlighted section.

Test this with print(“Hello World”), and then CTRL+ENTER (or click run in the top right)!
(5/10)

You should see this in your console window (the blue one from before).

This window shows outputs of code you run, but also allows you to type code line-by-line.

Let’s test this by typing 1+1 in the console, and pressing enter.
(6/10)

Now for the fun stuff! Don’t worry about the details of the code for now, but try typing the following into your script, and pressing CTRL+ENTER line-by-line:

install.packages(c("curl", "jsonlite")

library(curl)
library(jsonlite)

url <- "https://fantasy.premierleague.com/api/bootstrap-static/"

url_connection <- curl(url)

data <- fromJSON(url_connection)

players <- data$elements

write.csv(players, file = "FPL_players.csv")

The screenshot gives explanations.
(7/10)

That file should save by default to your “documents/R/“ folder, but if you can’t find it, run getwd() in your console and it should show you current working location.

Opening the file, we can now see all the data that FPL hold in the elements dataset, which currently contains all of last year’s summary data (this will change when the season starts). There are a lot of columns here, some are useful, some really aren’t!

(8/10)

For now I’d recommend having a play around with this data in excel, see what you can find and what’s interesting!

You’ll notice some odd quirks, which we’ll work around in the future, such as there being no “position” column, instead it’s “element_type”.
(9/10)

Hope this has been useful, my next two threads will probably be:

- Looking into all the different APIs that the FPL has available

- Starting to look into how we can analyse some of this data in R

If anyone has any issues at all with this guide, any questions, or any requests, then please get in touch!!

(10/10)