How to start learning python: The setup and starting guide
Oct 29, 2024Learning how to code is an essential skill for any analysis role in football. If you load up any analysis job description you will see "proficient in python or R" on 99% of them.
You do not need to be an expert.
If you’re able to download the software, understand the basics and use existing popular packages you’ll be well on your way
It can seem daunting to start as there are so many resources, and so many things to learn. So this article will aim to go through:
- Methods of writing code using Python
- Installing Anaconda for Jupyter Notebook
- Getting up and running using Jupyter Notebook
- Creating your first code script
This article is not a comprehensive guide on mastering Python, or an online course. If you're looking for something like this, then head over to see McKay Johns and his great work.
This guide is for anyone struggling to get setup and started in Python.
Choose Your Language
Now we've already clarified this article is for Python. But be aware that R is also a fantastic coding language.
In reality there isn't much between the languages. If you already have experience in one, then go with that.
If you’re starting from scratch - which you most likely are if you're reading this article. Then I like to recommended learning Python, as it more widely known language which can give you a skill desired by many industries, not just football.
Ways To Write Code
To write code you have a couple of different avenues:
- Can use a python script - This is file which contains python text code. This can be shared and uploaded to github to create apps. The problem with this is that it isn’t in a environment where you can see your output immediately.
- Use an open source web application that you can use to create and share documents that contain live code - this is where Jupyter Notebook comes in.
The main benefit of using Jupyter Notebook is that you're able to see an instant output of your code, without having to distribute or upload you code anywhere.
Installing Anaconda For Jupyter Notebook
Firstly we need to download Anaconda. It's a free, open-source distribution of Python and R programming languages. It is specifically designed for scientific computing, data science, and machine learning.
Included with anaconda distribution is the navigator interface. It provides an easy and user-friendly way to navigate, manage, and launch various applications and tools that are part of the Anaconda platform. This is where we can use Jupyter Notebook.
Here is the link to download Anaconda. It's completely free and open-source.
Click "download" as highlighted above and select your version depending on your computer and specification.
If your version doesn’t show, then click “additional installers” and the correct one should appear for you.
Save the download to an appropriate location, and it should take less than 5 minutes.
Go through the setup pages, you shouldn't need to change any of the options unless your device has multiple users.
Select you location for where you want it to be installed on your computer, and make sure you have space. It’s approx 4gb.
If you’re struggling this is great and simple video that should help.
Opening Jupyter Notebook
Head to the location where you saved the anaconda navigator app and open it.
Once opened, you want to find to launch for the Jupyter “Notebook” environment.
This will bring up your default web browser and open to a Jupyter page which is a file explorer system - See the screenshot below - please note that mine looks slightly different I have a lot of folders and files saved, so yours will look different too.
This works like your normal file explorer navigation, you can click into folders.
However you will only want to open “.ipynb” files, which are Jupyter Notebook files - these are what you’ll create when writing code using Jupyter Notebook.
Creating Your First Script
Using the Jupyter Notebook explorer menu, you should create a folder called "Python".
Feel free to save this where appropriate - in this example we’ll create the folder on our desktop.
Don't worry you can always rename the folder, move it elsewhere - just for now let's have a new Python folder on the desktop.
You do this buy clicking the "new" drop down in the top right corner, and clicking folder - you will want to click into the desktop folder before doing this, so it creates in the location we want.
You now want to repeat this process when inside the new Python folder which is on the desktop.
However, this time you want to go to the new drop down, then select "Python 3 (ipykernel)" - this will create an ".ipynb” file for your code script - essentially this is your new blank piece of paper for code.
This will then pop open a new tab in your browser as "Untitled - Jupyter Notebook" - It should look like the screenshot below.
Great! You've now opened your first notebook and are ready to start writing code!
Start Writing Code
Let's start from the simple basics. This is for someone with very very little or no Python knowledge.
I'll walk through these three simple actions using Python: printing a statement, basic calculations, and if statements..
Work through the examples below. To run the code you can either:
- Click the "run" button at the top of the page
- Press "shift" + "enter" on your keyboard - which is what I do.
You will have to do this for each line of code that you want to run. In the examples below we only need to run one line at a time.
However, when you complete all three actions, if you wanted to run all three - you'd need to run the code for all three lines one after each other.
Print Statement:
This code uses the pr
int
statement to display a message. The text inside the quotation marks is what will be shown on the screen. It's a way to communicate with your computer and make it say something.
Here is an example to help you.
Basic Calculation:
In this code, we introduce the concept of a variable. A variable is like a storage box that can hold information. In our case, we have two variables: num1
and num2
. We assign the value 5
to num1
and the value 7
to num2
.
Then, we create another variable named result
and use it to store the sum of num1
and num2
using the +
symbol. So, result
now holds the value 12
, which is the sum of 5
and 7
.
Finally, the print
statement is used to show a message on the screen. We combine the text with the values stored in num1
, num2
, and result
to create a meaningful message. The idea is that variables allow us to store and manipulate information in our programs.
In simple terms, you can think of variables as containers that hold different pieces of information, like numbers or text, and you can use them to perform calculations and keep track of data in your code.
Here is an example to help you.
IF statement
In this code, we have two variables team_goals
and opponent_goals
, representing the number of goals scored by the team and the opponent, respectively. The code uses an if-elif-else
statement to determine the match result based on a simple comparison.
- If
team_goals
are greater thanopponent_goals
, the result is set to "Win." - If
team_goals
are less thanopponent_goals
, the result is set to "Loss." - If neither condition is true (i.e., if the goals are equal), the result is set to "Draw."
The print
statement then displays the determined match result.
This example introduces the concept of making decisions in code using conditional statements, which is a crucial part of programming logic. It shows how you can use conditions to check different scenarios and react accordingly, in this case, to determine the result of a football match.
Here is an example to help you.
Hopefully you've made it through this article in one piece! I hope you've been able to start your Python journey.
While this just the start you've downloaded, installed and started learning Python which is the hardest part. Now it is time to just be consistent and continue the process.
My biggest advice is to use Python for something you are actually interested in and also have an end goal. What do you want to achieve by learning Python.
Resources
Assuming you're likely interested in football analysis, I would highly recommend checking out these resources to help you.
McKay Johns' Youtube channel - Plenty of great tutorials here and he is developing his own course which will be top level.
MPLSoccer - Essential package for football data visualisation.
Pandas - Data analysis and manipulation tool, built on top of the Python programming language.
Matplotlib - Comprehensive library for creating static, animated, and interactive visualisations in Python.
Statsbombpy - Package allowing you to connect with Statsbomb data (they have lots of free data too!)
Friends of tracking - YouTube channel is full of great resource of coding help.
Football edge discord server - An excellent community of 450+ scouts and analysts with a dedicated analysis channel.