Open-source, fast evolving, large community: Widely used in academic and scientific computing community.
Ties projects together: Code, data, documentation, output and analysis all in one place.
Encourages reproducible science:
Jupyter server for interactive computing Run on a local machine or cloud server to modify code and results on the fly.
Static rendering for presentations and publishing.
Diminishing returns to the accumulated factor $k$ implies convergence:
Did countries with low levels of income per capita in 1960 grow faster?
I found a dataset from World Penn Tables on this website (original data source here).
Let us import useful python libraries for data handling and plots and load the dataset into a pandas dataframe:
In [1]:
import matplotlib.pyplot as plt
%matplotlib inline
import pandas as pd
import seaborn as sns
from ipywidgets import interact
df = pd.read_stata(".\data\country.dta")
(in the future we will follow best practice and place library imports at the top of our notebooks).
Scatterplot of log GDP per capita and average growth 1960-2000:
In [2]:
g = sns.jointplot("lgdp60", "ggdp", data=df, kind="reg",
color ="b", size=7)
Same plot but excluding African countries:
In [3]:
g = sns.jointplot("lgdp60", "ggdp", data=df[df.cont !="Africa"], kind="reg",
color ="r", size=7)
There are ways to make plots like these interactive.
On the next slide I use ipywidgets: When the notebook is run on a jupyter server 'radio buttons' above the plot allow quick re-plotting for selected country regions.
Other libraries such as Bokeh and Plotly create plots with embedded javascript code that allow interactive plot elements even on HTML renderings (i.e. in most browsers even if you do not have a jupyter server running).
Here is how do do a dropdown menu. First we write a function to take a 'region' as argument that plots data only for that region (by specifying that filter in the pandas dataframe). We then use interact from the ipywidgets library to switch quickly between regions.
You'll only see this as truly interactive on a live notebook, not in a static HTML rendering of the same notebook.
In [4]:
def jplot(region):
sns.jointplot("lgdp60", "ggdp", data=df[df.cont == region],
kind="reg", color ="g", size=7)
plt.show();
In [5]:
interact(jplot, region=list(df.cont.unique()))
Out[5]: