2  numpy, pandas, matplotlib

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

The three lines above are the most common way you will start every project in this course.

The best resource I know to get acquainted with all three packages is Python Data Science Handbook, by Jake VanderPlas. This is a free online book, with excellent step by step examples.

2.1 pandas

We will primarily use the Pandas package to deal with data. Pandas has become the standard Python tool to manipulate time series, and you should get acquainted with its basic usage. This course will provide you the opportunity to learn by example, but I’m sure we will only scratch the surface, and you’ll be left with lots of questions.

I provide below a (non-comprehensive) list of useful tutorials, they are a good reference for the beginner and for the experienced user.

2.2 pyplot

Matplotlib, and its submodule pyplot, are probably the most common Python plotting tool. Pyplot is both great and horrible:

  • Great: you’ll have absolutely full control of everything you want to plot. The sky is the limit.
  • Horrible: you’ll cry as you do it, because there is so much to know, and it is not the most friendly plotting package.

Pyplot is object oriented, so you will usually manipulate the axes object like this.

import matplotlib.pyplot as plt

x = [1, 2, 3, 4, 5]
y = [1, 4, 2, 0, 3]

# Figure with two plots
fig, (ax1, ax2) = plt.subplots(1, 2, figsize = (8, 6))
# plot on the left
ax1.plot(x, y, color="tab:blue")
ax1.plot(x, y[::-1], color="tab:orange")
ax1.set(xlabel="date",
        ylabel="something",
        title="left panel")
# plot on the right
ax2.plot(x, y[::-1])
ax2.set(xlabel="date",
        ylabel="something else",
        title="right panel")
[Text(0.5, 0, 'date'),
 Text(0, 0.5, 'something else'),
 Text(0.5, 1.0, 'right panel')]

For the very beginners, you need to know that figure refers to the whole white canvas, and axes means the rectangle inside which something will be plotted:

The image above is good because it has 2 panels, and it’s easy to understand what going on. Sadly, they mixed the two terms, axis and axes.

  • axes is where the whole plot will be drawn. In the figure above it is the same as each panel.
  • axis is each of the vertical and horizontal lines, where you have ticks and numbers.

If you are new to all this, I recommend that you go to: