In [1]:
%load_ext load_style
%load_style images.css
In [2]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
In [3]:
df1 = pd.read_csv('data/police_locals.csv')
df1 = df1.replace('**',np.nan)
df1['all'] = df1['all'].astype('float')
df1['white'] = df1['white'].astype('float')
df1['non-white'] = df1['non-white'].astype('float')
df1['black'] = df1['black'].astype('float')
df1['hispanic'] = df1['hispanic'].astype('float')
In [4]:
df1
Out[4]:
In [5]:
len(df1)
Out[5]:
In [6]:
df1[['white','non-white']].describe()
Out[6]:
In [7]:
df2 = pd.melt(df1, id_vars=['city'], value_vars=['white','non-white'],
var_name='ethnicity', value_name='percent')
In [8]:
df2.head()
Out[8]:
In [9]:
sns.boxplot(x='ethnicity', y='percent', data=df2);
In [10]:
from IPython.display import Image
Image('images/538_local_police.png', width=600)
Out[10]:
This data comes from an article published on 538 on August 20 entitled, Most Police Don’t Live In The Cities They Serve. From the article:
In Ferguson, Missouri, where protests continue following the shooting of a teenager by a police officer this month, more than two-thirds of the civilian population is black. Only 11 percent of the police force is. The racial disparity is troubling enough on its own, but it’s also suggestive of another type of misrepresentation. Given Ferguson’s racial gap, it’s likely that many of its police officers live outside city limits.
The above dataset, published by 538 on this GitHub repository contains the fractions of police officers who live within the city they serve, for different races of police officers for 75 cities across the U.S. Now we can develop a story around that data:
Sometimes, these computational narratives, need to be used on contexts where the consumers no longer want to look at the code. Our collaborators at IBM have created a Jupyter incubation project (https://github.com/jupyter-incubator/dashboards) that turns any notebook into a live dashboard. You can play with the demo here (https://github.com/jupyter-incubator/showcase).