Code by Scott B Miles.
from pandas import *
from __future__ import division
pandas.set_option('display.height', 500)
pandas.set_option('display.max_rows', 500)
pandas.set_option('display.max_columns', 500)
pandas.set_option('display.width', 500)
pandas.set_option('display.mpl_style', False)
xls1 = ExcelFile('davies_1906_data.xlsx')
population = xls1.parse('nbrhd_population')
xls2 = ExcelFile('davies_1906_data.xlsx')
employment = xls2.parse('nbrhd_employment', parse_dates=[0])
population
Neighborhood | 1900 | 1910 | 1920 | |
---|---|---|---|---|
0 | South of Market | 61000 | 45000 | 75000 |
1 | Mission District | 78000 | 120000 | 210000 |
2 | Potrero Hill | 2502 | 11000 | 25000 |
3 | Outer Mission | 2100 | 19000 | 96000 |
4 | Western Addition-Pacific Heights | 86000 | 130000 | 250000 |
5 | North Beach | 21000 | 14000 | 40000 |
6 | Chinatown | 8211 | 14000 | 12000 |
7 | Downtown | 36000 | 18000 | 88000 |
8 | Panhandle Area | 5017 | 19000 | 16000 |
9 | Sunset | 7211 | 23000 | 60000 |
10 | Richmond | 21000 | 45000 | 78000 |
11 | Military | 1404 | 2102 | 19000 |
12 | All neighborhoods | 329445 | 460102 | 969000 |
figsize(12,10)
fig, ax = subplots()
x_loc = np.arange(13)
num_items = 3.0
margin = 0.1
width = (1.-2.*margin)/num_items
bar(x_loc, population['1900'], width, color='#A52A2A', label='1900')
bar(x_loc+width, population['1910'], width, color='#C97F7F', label='1910')
bar(x_loc+width*2.0, population['1920'], width, color='#E4BFBF', label='1920')
ax.tick_params(axis='y', labelsize=15)
ax.set_ylabel('San Francisco Population', fontsize=20)
ax.set_xticks(x_loc+width)
ax.set_xticklabels( ('South of Market', 'Mission District', 'Potrero Hill', 'Outer Mission', 'Pacific Heights', 'North Beach', 'Chinatown', 'Downtown', 'Panhandle Area', 'Sunset', 'Richmond', 'Military', 'All neighborhoods'), fontsize=20)
for label in ax.get_xticklabels():
label.set_horizontalalignment('right')
labels = ax.get_xticklabels()
for label in labels:
label.set_rotation(30)
ax.legend(loc='upper left', fontsize=30)
xlim(0,13)
(0, 13)
population['1900-1910 Change'] = 100.0*((population['1910'] - population['1900'])/ population['1900'])
population['1910-1920 Change'] = 100.0*((population['1920'] - population['1910'])/ population['1910'])
population
Neighborhood | 1900 | 1910 | 1920 | 1900-1910 Change | 1910-1920 Change | |
---|---|---|---|---|---|---|
0 | South of Market | 61000 | 45000 | 75000 | -26.229508 | 66.666667 |
1 | Mission District | 78000 | 120000 | 210000 | 53.846154 | 75.000000 |
2 | Potrero Hill | 2502 | 11000 | 25000 | 339.648281 | 127.272727 |
3 | Outer Mission | 2100 | 19000 | 96000 | 804.761905 | 405.263158 |
4 | Western Addition-Pacific Heights | 86000 | 130000 | 250000 | 51.162791 | 92.307692 |
5 | North Beach | 21000 | 14000 | 40000 | -33.333333 | 185.714286 |
6 | Chinatown | 8211 | 14000 | 12000 | 70.502984 | -14.285714 |
7 | Downtown | 36000 | 18000 | 88000 | -50.000000 | 388.888889 |
8 | Panhandle Area | 5017 | 19000 | 16000 | 278.712378 | -15.789474 |
9 | Sunset | 7211 | 23000 | 60000 | 218.957149 | 160.869565 |
10 | Richmond | 21000 | 45000 | 78000 | 114.285714 | 73.333333 |
11 | Military | 1404 | 2102 | 19000 | 49.715100 | 803.901047 |
12 | All neighborhoods | 329445 | 460102 | 969000 | 39.659731 | 110.605474 |
figsize(12,10)
fig, ax = subplots()
x_loc = np.arange(13)
num_items = 3.0
margin = 0.1
width = (1.-2.*margin)/num_items
bar(x_loc, population['1900-1910 Change'], width, color='#333399', label='1900 to 1910')
bar(x_loc+width, population['1910-1920 Change'], width, color='#9999CC', label='1910 to 1920')
ax.set_ylabel('San Francisco Population Change (%)')
ax.set_xticks(x_loc+width)
ax.set_xticklabels( ('South of Market', 'Mission District', 'Potrero Hill', 'Outer Mission', 'Western Addition-Pacific Heights', 'North Beach', 'Chinatown', 'Downtown', 'Panhandle Area', 'Sunset', 'Richmond', 'Military', 'All neighborhoods'))
for label in ax.get_xticklabels():
label.set_horizontalalignment('right')
labels = ax.get_xticklabels()
for label in labels:
label.set_rotation(30)
ax.legend()
xlim(0,13)
(0, 13)
employment_by_year = employment.set_index(['Year','Neighborhood'])
employment_by_year
Not working | Working class | Professional | ||
---|---|---|---|---|
Year | Neighborhood | |||
1900-01-01 | South of Market | 49 | 41 | 10 |
Mission District | 54 | 33 | 13 | |
Potrero Hill | 76 | 24 | 0 | |
Outer Mission | 29 | 71 | 0 | |
Western Addition-Pacific Heights | 53 | 27 | 20 | |
North Beach | 59 | 33 | 8 | |
Chinatown | 21 | 49 | 30 | |
Downtown | 35 | 42 | 22 | |
Panhandle Area | 68 | 20 | 12 | |
Sunset | 61 | 33 | 6 | |
Richmond | 56 | 20 | 24 | |
Military | 29 | 71 | 0 | |
All neighborhoods | 51 | 34 | 16 | |
1910-01-01 | South of Market | 27 | 61 | 13 |
Mission District | 54 | 32 | 14 | |
Potrero Hill | 57 | 34 | 10 | |
Outer Mission | 59 | 36 | 5 | |
Western Addition-Pacific Heights | 42 | 33 | 25 | |
North Beach | 57 | 36 | 7 | |
Chinatown | 28 | 34 | 39 | |
Downtown | 22 | 50 | 28 | |
Panhandle Area | 51 | 20 | 29 | |
Sunset | 55 | 30 | 15 | |
Richmond | 48 | 30 | 22 | |
Military | 38 | 52 | 10 | |
All neighborhoods | 46 | 35 | 19 | |
1920-01-01 | South of Market | 39 | 50 | 11 |
Mission District | 53 | 27 | 20 | |
Potrero Hill | 39 | 47 | 15 | |
Outer Mission | 60 | 30 | 10 | |
Western Addition-Pacific Heights | 46 | 28 | 26 | |
North Beach | 52 | 39 | 9 | |
Chinatown | 44 | 46 | 10 | |
Downtown | 32 | 29 | 39 | |
Panhandle Area | 67 | 13 | 20 | |
Sunset | 61 | 14 | 25 | |
Richmond | 56 | 18 | 26 | |
Military | 5 | 93 | 2 | |
All neighborhoods | 48 | 31 | 21 |
employment_by_year.ix['1900-01-01']
Not working | Working class | Professional | |
---|---|---|---|
Neighborhood | |||
South of Market | 49 | 41 | 10 |
Mission District | 54 | 33 | 13 |
Potrero Hill | 76 | 24 | 0 |
Outer Mission | 29 | 71 | 0 |
Western Addition-Pacific Heights | 53 | 27 | 20 |
North Beach | 59 | 33 | 8 |
Chinatown | 21 | 49 | 30 |
Downtown | 35 | 42 | 22 |
Panhandle Area | 68 | 20 | 12 |
Sunset | 61 | 33 | 6 |
Richmond | 56 | 20 | 24 |
Military | 29 | 71 | 0 |
All neighborhoods | 51 | 34 | 16 |
figsize(12,10)
fig, ax = subplots()
x_loc = np.arange(13)
width = 0.35
num_items = 3.0
margin = 0.1
width = (1.-2.*margin)/num_items
#1900
not_working1900=employment_by_year.ix['1900-01-01']['Not working']
working_class1900=employment_by_year.ix['1900-01-01']['Working class']
professional1900=employment_by_year.ix['1900-01-01']['Professional']
bar(x_loc, not_working1900, width, color='#252513')
bar(x_loc, working_class1900, width, color='#949470', bottom=not_working1900)
bar(x_loc, professional1900, width, color='#C2C2AD', bottom=not_working1900+working_class1900)
# 1910
not_working1910=employment_by_year.ix['1910-01-01']['Not working']
working_class1910=employment_by_year.ix['1910-01-01']['Working class']
professional1910=employment_by_year.ix['1910-01-01']['Professional']
bar(x_loc+width, not_working1910, width, color='#252513')
bar(x_loc+width, working_class1910, width, color='#949470', bottom=not_working1910)
bar(x_loc+width, professional1910, width, color='#C2C2AD', bottom=not_working1910+working_class1910)
# 1920
not_working1920=employment_by_year.ix['1920-01-01']['Not working']
working_class1920=employment_by_year.ix['1920-01-01']['Working class']
professional1920=employment_by_year.ix['1920-01-01']['Professional']
bar1 = bar(x_loc+2*width, not_working1920, width, color='#252513')
bar2 = bar(x_loc+2*width, working_class1920, width, color='#949470', bottom=not_working1920)
bar3 = bar(x_loc+2*width, professional1920, width, color='#C2C2AD', bottom=not_working1920+working_class1920)
ylim(0,100)
xlim(0,13)
ax.tick_params(axis='y', labelsize=15)
ax.set_ylabel('San Francisco Employment (%)', fontsize=20)
ax.set_xticks(x_loc+width)
ax.set_xticklabels( ('South of Market', 'Mission District', 'Potrero Hill', 'Outer Mission', 'Pacific Heights', 'North Beach', 'Chinatown', 'Downtown', 'Panhandle Area', 'Sunset', 'Richmond', 'Military', 'All neighborhoods'), fontsize=20)
for label in ax.get_xticklabels():
label.set_horizontalalignment('right')
labels = ax.get_xticklabels()
for label in labels:
label.set_rotation(30)
ax.legend( (bar3[0], bar2[0], bar1[0]), ('Professional', 'Working class', 'Not working'), loc='lower left', fontsize=25)
<matplotlib.legend.Legend at 0x9859ef0>
figsize(12,10)
fig, ax = subplots()
working_class_1900_1910 = 100.0*((working_class1910 - working_class1900) / working_class1900)
scatter1 = scatter(population['1900-1910 Change'], working_class_1900_1910, color='k', marker='o', s=40, label='1900 to 1910')
working_class_1910_1920 = 100.0*((working_class1920 - working_class1910) / working_class1910)
scatter2 = scatter(population['1910-1920 Change'], working_class_1910_1920, s=40, label='1910 to 1920')
ax.set_ylabel('Working Class Population Change (%)')
ax.set_xlabel('Total Population Change (%)')
ax.legend(loc='upper right')
<matplotlib.legend.Legend at 0x70c1070>