%load_ext pretty_jupyter

Installing Python

This walkthrough is part of the ECLR page.

Python is a multifaceted programming language that sees widespread use across diverse domains, including data analysis, statistics, machine learning, and general-purpose programming. Its intuitive syntax and extensive library ecosystem make it an attractive choice for novice and experienced users. This module aims to introduce the fundamental principles of Python, emphasizing its practical applications in Econometrics, Data Science and beyond.

But Python’s influence doesn’t stop at data science—it’s a driving force behind many websites and apps you use daily. Platforms like YouTube, Spotify, Dropbox, and Instagram are all built using Python and its web development framework Django . Whether you're streaming you favourite songs, sharing photos, or collaborating on data files, Python is working behind the scenes to make these experiences seamless. This connection between Python and the digital platforms we rely on highlights its extraordinary versatility: it’s a tool for advanced analytics and a foundation for building the modern web.

In this section, we’ll start with the basics: setting up Python (via installing Anaconda) and the IDE Visual Studio Code.

If you have done that already you can continue straight to this workthrough in which we will help you to import a real-life dataset (a database of car accidents in Greater Manchester, United Kingdom) which can be analysed with Python.

Installation on your computer

You can work using Python fully in the Cloud. That may be the right approach if you only need to use Python very occasionally. In a later section we will explain how you can do that. We recommend, however, that you install everything you need to work with Python on your computer. In that way yo can also work when you are offline.

In order to be in a position to work with Python on your computer we recommend that you go through the following steps.

  1. Install Anaconda (which installs Python as well)
  2. Install Visual Studio Code (VS Code)

Anaconda: Scientific Stack for Python

To run Python code, a Python interpreter is required—this is a tool that translates and executes Python instructions. In this guide, we will utilize the Anaconda distribution. Therefore, the first step is to install Anaconda, a widely used, open-source distribution of the Python programming language. Anaconda is a popular choice among researchers and professionals because it simplifies managing Python environments, especially for data science, machine learning, and scientific computing tasks. It provides an integrated platform that streamlines package management and deployment, addressing the complexities of handling dependencies. Notably, Anaconda includes over 1,500 pre-installed libraries that are essential for these domains, such as:

  • NymPy- for numerical computing.
  • pandas- for data manipulation and analysis.
  • matplotlib and seaborn- for data visualisation.
  • scikit-learn- for machine learning tasks.
  • SciPy- for scientific and technical computing.

For beginners, Anaconda is especially advantageous as it simplifies the process of installing and managing libraries with complex dependencies. Moreover, it includes conda, a robust package and environment manager that supports the installation of binary packages and the creation of isolated environments.

A YouTube video walking you through the Anaconda installation is available from Arthur Turrell.

Visual Studio Code

This is an integrated development environment (IDE). It makes it easier to work on your code and importantly easily interact with your data. There are many different IDEs available. The one we have most experience with is Visual Studio Code and therefore we recommend that one. It works with all major operating systems and it is free software.

A YouTube video walking you through the installation of Visual Studio Code is available from Arthur Turrell. It will also show you how to run python code in interactive mode and in jupyter notebooks (see below).

Other popular IDEs are Spyder and PyCharm.

Working online

If you do not wish to install Python, Anaconda and VS Code on your computer (or if something does not work out with your installation) you can also work on the cloud. We think that for regular work this is not the recommended mode of working, and hence we will not go into any detail here. But here is a set of services (all free for reasonably small usage) you could use.

Tool Type Key Features Best For
Jupyter Notebook Interactive Web-Based Environment Code execution, Markdown documentation, data visualization, inline outputs Teaching, data analysis, and walkthroughs
JupyterLab Advanced Web-Based Environment Multi-document interface, side-by-side notebooks, consoles, and file viewers Multitasking with enhanced flexibility
GitHub Codespaces Web-based IDE requires a Github Account. After accessing Codespaces, you choose a Template. Select the "Jupyter Notebook" quick-start template and hit “Use this template.” Your Codespace will load in an online version of Visual Studio Code, pre-installed with Python. You can check the Python version by running Python --version in the terminal, typically located at the bottom panel. working with GitHub repositories

Jupyter Notebooks

You can write python code scripts (files with extension .py) that can be executed by Python. Here, however, we recommend that you write your code in a Jupyter Notebook. Jupyter Notebooks are particularly useful as they will help you write Python code, analyse data, and document your thought process- all in one file! This makes it an invaluable tool for both beginners and professionals in Python. More specifically, Jupyter Notebooks

  • simplify the learning process by allowing you to see the code and its output side by side.
  • support step-by-step workflows, making it ideal for better understanding data analysis, econometrics, and machine learning procedures.
  • combine code execution, documentation, and visualisation in one interactive.

For all these reasons we will use Jupyter notebooks on the ECLR page. If you come from programming in R then you will find that Jupyter Notebooks have a lot in common with R markdown files. We will use the IDE you installed locally (VS Studio) to write these. They can also written online.

Summary

At this stage, all you have done is to install the software you need to work in Python. In this workthrough we will help you to import a real-life dataset (a database of car accidents in Greater Manchester, United Kingdom) which can be analysed with Python. Please go on and start your Python learning journey.