Below is the analysis for “New Wards, New Problems”.

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import statsmodels.regression.linear_model as sm

How Toronto’s New Wards Change Voter Representation

This analysis will look at the census profile data for each ward

Factors to Analyze:

  • Overall increase in ward size
  • Income
  • Language
  • First-gen immigrants
  • Race
  • Education
  • Employment
  • Rent vs. Home owners

Overall Increase in Size of Ward

full_before = pd.read_csv('./Data/FullPop/full_47.csv', index_col=0).transpose()
full_after = pd.read_csv('./Data/FullPop/full_25.csv', index_col=0).transpose()
full_before.head()
total
Toronto 2731570
Ward 1 60735
Ward 2 57210
Ward 3 64065
Ward 4 66060
full_after.head()
total
Toronto 2731570
Ward 1 118040
Ward 2 118020
Ward 3 129080
Ward 4 108805
toronto_pop = full_after.loc['Toronto'][0]
print('The population of Toronto is ', toronto_pop)
The population of Toronto is  2731570
avg_ward_before = np.mean(full_before[1:].total)
avg_ward_after = np.mean(full_after[1:].total)
label = ['before', 'after']
plt.bar(label, [avg_ward_before, avg_ward_after])
plt.ylabel('Average Ward Size')
plt.title('The average ward increased by {} people\nwhich is a factor of {}'
          .format(int(avg_ward_after - avg_ward_before),round(avg_ward_after/avg_ward_before,3)))
plt.show()

png

Function to calculate average increase (in group vs. out group)

def scale_populations(df_before, df_after, full_before = full_before, full_after = full_after):
    #scale popualtion
    scale_factors_before = full_before[1:].total/df_before[1:].total
    df_before_scaled = df_before[1:].mul(scale_factors_before, axis = 0)

    scale_factors_after = full_after[1:].total/df_after[1:].total
    df_after_scaled = df_after[1:].mul(scale_factors_after, axis = 0)
    return df_before_scaled, df_after_scaled
def get_increases(total_before, protected_before, majority_before, total_after, protected_after, majority_after):
    # get protected group ward size increase
    avg_ward_size_protected_before = np.average(total_before, weights = protected_before)
    avg_ward_size_protected_after = np.average(total_after, weights = protected_after)
    avg_increase_protected = avg_ward_size_protected_after - avg_ward_size_protected_before

    # get majority group ward size increase
    avg_ward_size_majority_before = np.average(total_before, weights = majority_before)
    avg_ward_size_majority_after = np.average(total_after, weights = majority_after)
    avg_increase_majority = avg_ward_size_majority_after - avg_ward_size_majority_before

    return int(avg_increase_protected), int(avg_increase_majority)

Income

The low income threshold is provided by the census data and needs to be defined.

income_before = pd.read_csv('./Data/Income/Income_47.csv', index_col=0).transpose()
income_after = pd.read_csv('./Data/Income/Income_25.csv', index_col=0).transpose()
income_before.head()
total low_income prop_low_income
Toronto 2691665.0 543365.0 20.2
Ward 1 60040.0 13875.0 23.1
Ward 2 56300.0 11345.0 20.2
Ward 3 63165.0 7575.0 12.0
Ward 4 65335.0 7850.0 12.0
income_after.head()
total low_income prop_low_income
Toronto 2691665.0 543365.0 20.2
Ward 1 116955.0 26300.0 22.5
Ward 2 116055.0 13525.0 11.7
Ward 3 127525.0 19640.0 15.4
Ward 4 106445.0 18535.0 17.4
income_before, income_after = scale_populations(income_before, income_after)
income_before.head()
total low_income prop_low_income
Ward 1 60735.0 14035.611676 23.367397
Ward 2 57210.0 11528.373890 20.526501
Ward 3 64065.0 7682.931608 12.170981
Ward 4 66060.0 7937.108747 12.133160
Ward 5 49520.0 7285.027545 14.852969
# calculated high income
income_before['high_income'] = income_before.total - income_before.low_income
income_after['high_income'] = income_after.total - income_after.low_income
# Initialize params
total_before = income_before.total
protected_before = income_before.low_income
majority_before = income_before.high_income

total_after = income_after.total
protected_after = income_after.low_income
majority_after = income_after.high_income

protected_increase, majority_increase = get_increases(total_before, protected_before, majority_before, total_after, protected_after, majority_after)
print("If you are low-income, your ward size increased by {} people on average".format(protected_increase))
print("If you are high-income, your ward size increased by {} people on average".format(majority_increase))
print("This is a disparity of {} people on average".format(protected_increase-majority_increase))
If you are low-income, your ward size increased by 50281 people on average
If you are high-income, your ward size increased by 49989 people on average
This is a disparity of 292 people on average
threshold = .5

# lost majorities
prop_protected_before = protected_before / total_before
print("wards with majority low-income before: {}/47".format(len([p for p in prop_protected_before if p > threshold])))

prop_protected_after = protected_after / total_after
print("wards with majority low-income before: {}/25".format(len([p for p in prop_protected_after if p > threshold])))
wards with majority low-income before: 0/47
wards with majority low-income before: 0/25

Visible Minority

race_before = pd.read_csv('./Data/Race/race_before.csv', index_col=0).transpose()
race_after = pd.read_csv('./Data/Race/race_after.csv', index_col=0).transpose()
race_before.head()
total visible_minority south_asian chinese black filipino latin_american arab southeast_asian west_asian korean japanese other_visible_minoirty multiple_visible_minorities not_visible_minority
Toronto 2691665 1385850 338960 299465 239855 152715 77165 36030 41650 60320 41640 13410 36975 47670 1305815
Ward 1 60045 49875 20615 700 13935 2190 2410 3120 1065 1715 140 40 2715 1235 10165
Ward 2 56295 35405 12210 805 11990 2050 3045 525 925 1015 325 100 1300 1115 20895
Ward 3 63170 18215 4020 2450 3320 1975 1630 675 540 840 1380 275 380 735 44955
Ward 4 65330 18755 4315 1620 5135 1375 2495 385 305 590 1055 285 555 650 46575
race_after.head()
total visible_minority south_asian chinese black filipino latin_american arab southeast_asian west_asian korean japanese other_visible_minoirty multiple_visible_minorities not_visible_minority
Toronto 2691665 1385855 338965 299465 239850 152715 77165 36030 41645 60325 41640 13415 36975 47670 1305815
Ward 1 116955 88495 33825 1635 27365 4460 5605 3705 2015 2790 480 145 4115 2355 28460
Ward 2 116055 31445 6910 3530 6825 2835 3725 885 715 1315 2165 500 805 1235 84615
Ward 3 127525 35355 7050 4445 6325 4255 3060 1155 1315 915 2425 655 2185 1575 92165
Ward 4 106445 27865 5010 3710 5625 2805 2320 700 1595 585 1015 730 2255 1515 78580
race_before, race_after = scale_populations(race_before, race_after)
race_before.head()
total visible_minority south_asian chinese black filipino latin_american arab southeast_asian west_asian korean japanese other_visible_minoirty multiple_visible_minorities not_visible_minority
Ward 1 60735.0 50448.132651 20851.894829 708.043967 14095.132401 2215.166125 2437.694229 3155.853110 1077.238321 1734.707719 141.608793 40.459655 2746.199101 1249.191856 10281.809893
Ward 2 57210.0 35980.460965 12408.457234 818.084199 12184.881428 2083.320011 3094.492406 533.533173 940.034639 1031.497469 330.282441 101.625366 1321.129763 1133.122835 21234.620304
Ward 3 64065.0 18473.072265 4076.955833 2484.711889 3367.038151 2002.982033 1653.094032 684.563479 547.650784 851.901219 1399.552003 278.896232 385.383885 745.413567 45591.927735
Ward 4 66060.0 18964.569111 4363.215980 1638.101944 5192.378693 1390.364304 2522.879229 389.302005 308.408082 596.592683 1066.788612 288.184601 561.201592 657.263126 47095.430889
Ward 5 49520.0 14398.286064 3324.235870 1606.545603 2404.766374 1404.464395 1111.446644 464.786778 535.515201 399.110386 1530.765150 267.757600 823.480922 535.515201 35121.713936
race_before.columns
Index(['total', 'visible_minority', 'south_asian', 'chinese', 'black',
       'filipino', 'latin_american', 'arab', 'southeast_asian', 'west_asian',
       'korean', 'japanese', 'other_visible_minoirty',
       'multiple_visible_minorities', 'not_visible_minority'],
      dtype='object')
# Initialize params
protected = ['visible_minority',
             'south_asian',
             'chinese',
             'black',
             'filipino',
             'latin_american',
             'arab',
             'southeast_asian',
             'west_asian',
             'korean',
             'japanese',
             'other_visible_minoirty',
             'multiple_visible_minorities']
data = []
for col in protected:
    total_before = race_before.total
    protected_before = race_before[col]
    majority_before = race_before.not_visible_minority

    total_after = race_after.total
    protected_after = race_after[col]
    majority_after = race_after.not_visible_minority

    protected_increase, majority_increase = get_increases(total_before,
                                                          protected_before,
                                                          majority_before,
                                                          total_after,
                                                          protected_after,
                                                          majority_after)
    data.append([col, protected_increase, majority_increase])
race_results =pd.DataFrame(data, columns = ['group', 'protected_increase', 'majority_increase'])
race_results['disparity'] = race_results.protected_increase - race_results.majority_increase
race_results[['protected_increase','group']].plot(x = 'group', kind = 'bar')
plt.ylabel('average ward size increase')
plt.hlines(51144, xmin = -1, xmax = 15, label = "white increase")
plt.legend(loc = 3)
plt.ylim(45000,57000)
plt.title("Some groups (S. asians, chinese, filipino) have more representation \n while others (L. american, Korean, SE. Asian) have less")
plt.show()

png

for col in protected:
    print("---------------------------")
    total_before = race_before.total
    protected_before = race_before[col]
    prop_protected_before = protected_before/total_before
    print("wards with majority {} before: {}/47={}"
          .format(col,
                  len([p for p in prop_protected_before if p > threshold]),
                  len([p for p in prop_protected_before if p > threshold])/47
                 )
         )

    total_after = race_after.total
    protected_after = race_after[col]
    prop_protected_after = protected_after/total_after
    print("wards with majority {} after: {}/47={}"
          .format(col,
                  len([p for p in prop_protected_after if p > threshold]),
                  len([p for p in prop_protected_after if p > threshold])/25
                 )
         )
---------------------------
wards with majority visible_minority before: 24/47=0.5106382978723404
wards with majority visible_minority after: 12/47=0.48
---------------------------
wards with majority south_asian before: 0/47=0.0
wards with majority south_asian after: 0/47=0.0
---------------------------
wards with majority chinese before: 1/47=0.02127659574468085
wards with majority chinese after: 0/47=0.0
---------------------------
wards with majority black before: 0/47=0.0
wards with majority black after: 0/47=0.0
---------------------------
wards with majority filipino before: 0/47=0.0
wards with majority filipino after: 0/47=0.0
---------------------------
wards with majority latin_american before: 0/47=0.0
wards with majority latin_american after: 0/47=0.0
---------------------------
wards with majority arab before: 0/47=0.0
wards with majority arab after: 0/47=0.0
---------------------------
wards with majority southeast_asian before: 0/47=0.0
wards with majority southeast_asian after: 0/47=0.0
---------------------------
wards with majority west_asian before: 0/47=0.0
wards with majority west_asian after: 0/47=0.0
---------------------------
wards with majority korean before: 0/47=0.0
wards with majority korean after: 0/47=0.0
---------------------------
wards with majority japanese before: 0/47=0.0
wards with majority japanese after: 0/47=0.0
---------------------------
wards with majority other_visible_minoirty before: 0/47=0.0
wards with majority other_visible_minoirty after: 0/47=0.0
---------------------------
wards with majority multiple_visible_minorities before: 0/47=0.0
wards with majority multiple_visible_minorities after: 0/47=0.0
race_before.columns
Index(['total', 'visible_minority', 'south_asian', 'chinese', 'black',
       'filipino', 'latin_american', 'arab', 'southeast_asian', 'west_asian',
       'korean', 'japanese', 'other_visible_minoirty',
       'multiple_visible_minorities', 'not_visible_minority'],
      dtype='object')
races = ['total', 'visible_minority', 'south_asian', 'chinese', 'black',
       'filipino', 'latin_american', 'arab', 'southeast_asian', 'west_asian',
       'korean', 'japanese', 'other_visible_minoirty',
       'multiple_visible_minorities', 'not_visible_minority']
for idx, ward in race_before.itterrows():

    for col in race_before:

total visible_minority south_asian chinese black filipino latin_american arab southeast_asian west_asian korean japanese other_visible_minoirty multiple_visible_minorities not_visible_minority
Ward 1 60735.0 50448.132651 20851.894829 708.043967 14095.132401 2215.166125 2437.694229 3155.853110 1077.238321 1734.707719 141.608793 40.459655 2746.199101 1249.191856 10281.809893
Ward 2 57210.0 35980.460965 12408.457234 818.084199 12184.881428 2083.320011 3094.492406 533.533173 940.034639 1031.497469 330.282441 101.625366 1321.129763 1133.122835 21234.620304
Ward 3 64065.0 18473.072265 4076.955833 2484.711889 3367.038151 2002.982033 1653.094032 684.563479 547.650784 851.901219 1399.552003 278.896232 385.383885 745.413567 45591.927735
Ward 4 66060.0 18964.569111 4363.215980 1638.101944 5192.378693 1390.364304 2522.879229 389.302005 308.408082 596.592683 1066.788612 288.184601 561.201592 657.263126 47095.430889
Ward 5 49520.0 14398.286064 3324.235870 1606.545603 2404.766374 1404.464395 1111.446644 464.786778 535.515201 399.110386 1530.765150 267.757600 823.480922 535.515201 35121.713936
Ward 6 67560.0 19040.188934 3373.441296 2476.896086 3809.050832 2593.396311 1732.307692 597.696806 704.066577 476.131354 658.479532 339.370220 1362.546109 916.806118 48514.745839
Ward 7 47345.0 33097.383524 8161.548073 1072.832486 9033.851122 2717.173867 5293.977128 426.125053 3298.709233 681.800085 210.555909 60.158831 1067.819250 1057.792778 14252.629712
Ward 8 54200.0 42771.502687 6989.660923 2465.462294 14426.218269 2862.145636 4192.792292 974.133778 5568.630721 1129.794330 241.022790 55.234389 2088.864184 1777.543079 11428.497313
Ward 9 47470.0 27812.377785 2125.148348 1373.326998 7057.096400 5653.696547 4766.547355 551.335656 3242.856087 786.906346 250.607116 50.121423 746.809207 1222.962728 19652.610073
Ward 10 68535.0 26801.171410 1809.255460 2141.876241 2444.258769 13073.004633 1436.317009 594.685639 539.248842 1647.984778 1547.190602 186.469226 428.375248 952.504964 41733.828590
Ward 11 62615.0 34228.722586 2847.748644 1540.419196 14856.937768 2883.218823 5538.415068 364.836125 2994.696528 349.634620 324.298778 228.022578 1109.709881 1200.918912 28381.210245
Ward 12 53055.0 29439.518487 3725.558899 942.794497 12038.370593 3923.241617 4298.331900 233.164230 2088.340499 258.508169 131.788478 70.963027 669.079966 1064.445400 23615.481513
Ward 13 56895.0 23619.889991 1775.082958 1646.825518 5284.206492 8839.502705 2385.588368 220.602795 943.974752 405.293508 410.423805 169.299820 615.635708 918.323264 33275.110009
Ward 14 57500.0 12905.611135 1275.554589 3161.374511 1060.461070 3426.489778 955.415398 250.108743 245.106568 820.356677 655.284906 290.126142 140.060896 620.269682 44594.388865
Ward 15 63520.0 17250.069344 1592.865667 2627.460087 3877.168199 3247.192388 2386.737623 379.009837 568.514756 343.157555 548.027737 384.131592 353.401064 947.524593 46264.808902
Ward 16 67990.0 24898.952085 3081.528549 3041.247130 5775.348441 3026.141598 4481.307858 302.110642 1857.980449 287.005110 483.377027 261.829223 991.929941 1304.110938 43091.047915
Ward 17 66135.0 14452.375905 2445.709112 2475.965307 2803.740755 1084.180328 1603.578345 474.013725 635.380099 408.458635 816.917270 534.526115 373.159741 791.703774 51682.624095
Ward 18 72620.0 23274.381719 4016.924610 3835.982060 4409.828433 2305.725066 1871.462946 387.734036 1664.671460 336.036164 547.997437 387.734036 2243.687620 1256.258276 49350.788069
Ward 19 72460.0 21057.318239 3123.188019 7764.663198 2394.613978 1197.306989 1609.995781 647.055266 764.238504 529.872029 998.604978 484.017719 473.827872 1075.028829 51402.681761
Ward 20 36400.0 15977.921542 3281.761872 5135.581555 2059.242946 691.424639 946.951136 761.569167 440.908465 856.765313 576.187199 250.516173 270.557467 711.465933 20422.078458
Ward 21 28665.0 11310.245592 1763.841310 2439.464736 3218.236776 732.355164 593.104534 371.335013 376.492443 443.539043 293.973552 226.926952 304.288413 541.530227 17354.754408
Ward 22 42230.0 22242.500000 5032.750000 8061.625000 1870.625000 758.500000 773.875000 1768.125000 410.000000 753.375000 1240.250000 471.500000 292.125000 804.625000 19987.500000
Ward 23 47560.0 26689.101558 7962.581501 3500.382363 5187.503592 3941.872030 1350.748149 904.002652 961.816775 688.513648 567.629572 194.465687 583.397060 856.700188 20870.898442
Ward 24 42390.0 17966.199095 1939.411765 8674.072398 1827.522624 836.504525 724.615385 495.509050 825.848416 404.932127 793.880090 538.133484 239.762443 676.662896 24418.472851
Ward 25 43945.0 18742.302280 3271.086299 7380.388462 1252.212724 822.882647 914.881949 935.326239 444.663294 960.881600 1482.210979 378.219353 255.553617 643.995115 25197.586648
Ward 26 57700.0 14157.182198 2988.282846 3024.162743 1527.458470 1250.670694 1086.648308 507.444257 246.033579 1127.653904 994.385716 553.575553 235.782180 615.083948 43542.817802
Ward 27 59675.0 22609.876231 3009.625747 8998.730740 1683.179675 1512.349499 1024.981056 547.661446 251.220847 2436.842216 1748.497095 401.953355 256.245264 733.564873 37065.123769
Ward 28 55840.0 37191.280101 3649.871447 15130.284266 899.829803 1193.032772 616.737280 1162.701430 429.694007 5995.495202 6465.630998 717.841753 146.601485 783.559660 18648.719899
Ward 29 57765.0 39831.305908 3321.803501 14874.803501 1319.620569 4105.486214 1046.595624 773.570678 470.209628 6684.055142 5708.243764 333.697155 232.576805 950.531291 17928.638074
Ward 30 48580.0 33923.643784 3395.922980 17904.851402 1601.370866 940.487652 716.804102 665.966932 391.446212 4041.555044 2984.141900 305.023022 167.762662 803.227292 14656.356216
Ward 31 61490.0 43527.192982 7802.280702 16557.894737 3171.087719 4320.105263 1144.000000 2117.403509 501.754386 4320.105263 1615.649123 275.964912 446.561404 1244.350877 17957.789474
Ward 32 68245.0 35022.395067 7128.182899 5896.213877 6448.825496 4365.124805 1738.952158 2960.781517 344.748533 2631.242478 1084.943912 471.494317 765.544536 1176.200877 33227.674764
Ward 33 55425.0 33854.765174 16237.297446 2257.999176 3318.497665 3739.652568 750.975007 1070.646800 421.154902 3993.360341 492.193079 142.076353 461.748146 964.089536 21565.160670
Ward 34 58220.0 13911.595002 2899.712193 3622.131840 1861.233951 1525.108143 802.688496 331.109005 456.529082 481.613098 406.361051 561.881947 311.041792 647.167600 44308.404998
Ward 35 65240.0 30686.288020 12376.769088 3877.548107 5355.673495 3047.368094 1113.656114 556.828057 485.959032 1300.952824 516.331471 410.027933 632.759156 1002.290503 34553.711980
Ward 36 60615.0 22461.344113 3098.644517 10128.024255 3481.508338 1010.760485 689.154876 290.976503 1036.284740 377.758969 296.081354 479.855988 398.178373 1169.010864 38153.655887
Ward 37 54020.0 12636.434239 2833.869131 2884.293849 2430.471390 1134.556147 620.224027 287.420891 327.760665 236.996173 347.930552 363.057967 398.355269 766.455708 41383.565761
Ward 38 64865.0 27787.625246 10957.925285 2683.365317 5948.296500 3096.583169 775.421156 357.101848 464.232403 897.856076 153.043649 403.014943 851.942981 1198.841919 37072.273299
Ward 39 65460.0 44999.934722 17295.927883 4262.937519 8866.706559 7956.126826 920.753808 529.051912 707.098228 1108.974200 234.003730 325.570407 1383.674231 1409.109419 20465.152316
Ward 40 67795.0 45218.641260 16404.878824 5096.415214 5841.861022 9143.121026 1146.059541 2246.479542 608.527190 1475.678435 223.126636 197.771337 1460.465255 1369.186177 22571.287680
Ward 41 70535.0 52696.741447 21371.143810 8435.977820 7392.984198 7280.504494 1155.473326 756.681647 557.285807 2014.409249 393.678965 199.395839 1528.701435 1620.730284 17833.145839
Ward 42 61245.0 48154.272810 9503.534483 24493.958093 4476.412308 3728.659462 651.757548 1076.157812 363.771655 1141.838805 419.347880 242.514437 732.595694 1328.777017 13090.727190
Ward 43 69375.0 59607.382366 8018.497142 40534.850484 3249.093008 2679.611917 396.602902 1418.618074 477.957344 559.311785 320.333113 193.216799 538.973175 1220.316623 9767.617634
Ward 44 62360.0 57302.827021 15935.152056 27121.618685 5304.974455 4389.626145 490.545779 561.346201 520.888817 414.688184 116.314979 96.086287 885.005271 1471.637337 5052.115806
Ward 45 63585.0 57336.241627 28998.849003 2876.333044 11430.166680 6734.828592 891.963906 526.158484 360.794389 861.897707 75.165498 45.099299 2450.395224 2084.589802 6248.758373
Ward 46 57635.0 43308.282824 20591.500832 1953.643251 9778.312604 4674.608917 954.104844 605.780853 530.058246 1211.561706 146.397040 146.397040 1554.837523 1161.079968 14321.669002
Ward 47 49230.0 27500.163479 11231.890808 2475.166564 5836.128933 3315.407156 779.500308 339.133251 283.454658 587.156076 253.084516 222.714374 1184.435534 987.029611 21729.836521

Language

lang_before = pd.read_csv('./Data/Language/language_before.csv', index_col=0).transpose()
lang_after = pd.read_csv('./Data/Language/language_after.csv', index_col=0).transpose()
lang_before.head()
total english non_english
Toronto 2691665 2557220 134445
Ward 1 60040 56105 3940
Ward 2 56300 54115 2180
Ward 3 63165 61410 1755
Ward 4 65330 63855 1475
lang_after.head()
total english non_english
Toronto 2691665 2557220 134445
Ward 1 116960 110765 6185
Ward 2 116055 113025 3030
Ward 3 127520 124255 3265
Ward 4 106445 103735 2710
lang_before, lang_after = scale_populations(lang_before, lang_after)
lang_before.head()
total english non_english
Ward 1 60735.0 56754.449950 3985.607928
Ward 2 57210.0 54989.682948 2215.236234
Ward 3 64065.0 62284.994063 1780.005937
Ward 4 66060.0 64568.518292 1491.481708
Ward 5 49520.0 48145.847786 1384.256274
# Initialize params
total_before = lang_before.total
protected_before = lang_before.non_english
majority_before = lang_before.english

total_after = lang_after.total
protected_after = lang_after.non_english
majority_after = lang_after.english

protected_increase, majority_increase = get_increases(total_before, protected_before, majority_before, total_after, protected_after, majority_after)
print("If you are english speaking, your ward size increased by {} people on average".format(protected_increase))
print("If you are not english speaking, your ward size increased by {} people on average".format(majority_increase))
print("This is a disparity of {} people on average".format(protected_increase-majority_increase))
If you are english speaking, your ward size increased by 47397 people on average
If you are not english speaking, your ward size increased by 50187 people on average
This is a disparity of -2790 people on average
# lost majorities
prop_protected_before = protected_before / total_before
print("Wards with majority not english speaking before: {}/47".format(len([p for p in prop_protected_before if p > threshold])))

prop_protected_after = protected_after / total_after
print("Wards with majority not english speaking before: {}/25".format(len([p for p in prop_protected_after if p > threshold])))
Wards with majority not english speaking before: 0/47
Wards with majority not english speaking before: 0/25

First generation immigrants

immigrant_before = pd.read_csv('./Data/Immigration/immigration_before.csv', index_col=0).transpose()
immigrant_after = pd.read_csv('./Data/Immigration/immigration_after.csv', index_col=0).transpose()
immigrant_before.head()
total first_gen second_gen_plus
Toronto 2691665 1377465 1314205
Ward 1 60040 39450 20585
Ward 2 56295 30490 25810
Ward 3 63165 28290 34870
Ward 4 65335 26895 38440
immigrant_after.head()
total first_gen second_gen_plus
Toronto 2691665 1377465 1314205
Ward 1 116960 71535 45425
Ward 2 116055 50030 66025
Ward 3 127525 51980 75545
Ward 4 106445 37785 68650
immigrant_before, immigrant_after = scale_populations(immigrant_before, immigrant_after)
immigrant_before.head()
total first_gen second_gen_plus
Ward 1 60735.0 39906.658061 20823.284061
Ward 2 57210.0 30985.574207 26229.507061
Ward 3 64065.0 28693.087153 35366.841605
Ward 4 66060.0 27193.444555 38866.555445
Ward 5 49520.0 21839.926546 27685.125485
# Initialize params
total_before = immigrant_before.total
protected_before = immigrant_before.first_gen
majority_before = immigrant_before.second_gen_plus

total_after = immigrant_after.total
protected_after = immigrant_after.first_gen
majority_after = immigrant_after.second_gen_plus

protected_increase, majority_increase = get_increases(total_before, protected_before, majority_before, total_after, protected_after, majority_after)
print("If you are first gen canadian, your ward size increased by {} people on average".format(protected_increase))
print("If you are not first gen canadian, your ward size increased by {} people on average".format(majority_increase))
print("This is a disparity of {} people on average".format(protected_increase-majority_increase))
If you are first gen canadian, your ward size increased by 49799 people on average
If you are not first gen canadian, your ward size increased by 50308 people on average
This is a disparity of -509 people on average
# lost majorities
prop_protected_before = protected_before / total_before
print("Wards with majority first gen canadian before: {}/47={}"
      .format(len([p for p in prop_protected_before if p > threshold]),
             len([p for p in prop_protected_before if p > threshold])/47))

prop_protected_after = protected_after / total_after
print("Wards with majority first gen canadian after: {}/25={}"
      .format(len([p for p in prop_protected_after if p > threshold]),
             len([p for p in prop_protected_after if p > threshold])/25))
Wards with majority first gen canadian before: 27/47=0.574468085106383
Wards with majority first gen canadian after: 12/25=0.48

Education

education_before = pd.read_csv('./Data/Education/education_before.csv', index_col=0).transpose()
education_after = pd.read_csv('./Data/Education/education_after.csv', index_col=0).transpose()
education_before.head()
total post_secondary no_post_secondary
Toronto 2294785 1356355 938435
Ward 1 48650 20630 28020
Ward 2 46555 21875 24680
Ward 3 53825 32465 21365
Ward 4 55085 33430 21660
education_after.head()
total post_secondary no_post_secondary
Toronto 2294790 1356355 938430
Ward 1 95295 42350 52940
Ward 2 98790 58480 40305
Ward 3 110720 71165 39555
Ward 4 90620 62430 28195
education_before, education_after = scale_populations(education_before, education_after)
education_before.head()
total post_secondary no_post_secondary
Ward 1 60735.0 25754.636177 34980.363823
Ward 2 57210.0 26881.511116 30328.488884
Ward 3 64065.0 38641.341849 25429.609382
Ward 4 66060.0 40090.511028 25975.485159
Ward 5 49520.0 32661.128497 16864.741584
# Initialize params
total_before = education_before.total
protected_before = education_before.no_post_secondary
majority_before = education_before.post_secondary

total_after = education_after.total
protected_after = education_after.no_post_secondary
majority_after = education_after.post_secondary

protected_increase, majority_increase = get_increases(total_before, protected_before, majority_before, total_after, protected_after, majority_after)
print("If you don't have a post-secondary degree, your ward size increased by {} people on average".format(protected_increase))
print("If you have a post-secondary degree, your ward size increased by {} people on average".format(majority_increase))
print("This is a disparity of {} people on average".format(protected_increase-majority_increase))
If you don't have a post-secondary degree, your ward size increased by 49261 people on average
If you have a post-secondary degree, your ward size increased by 50598 people on average
This is a disparity of -1337 people on average
# lost majorities
prop_protected_before = protected_before / total_before
print("Wards with majority no post-secondary degree before: {}/47={}"
      .format(len([p for p in prop_protected_before if p > threshold]),
             len([p for p in prop_protected_before if p > threshold])/47))

prop_protected_after = protected_after / total_after
print("Wards with majority no post-secondary degree after: {}/25={}"
      .format(len([p for p in prop_protected_after if p > threshold]),
             len([p for p in prop_protected_after if p > threshold])/25))
Wards with majority no post-secondary degree before: 13/47=0.2765957446808511
Wards with majority no post-secondary degree after: 5/25=0.2

Renter vs. Home Owner

housing_before = pd.read_csv('./Data/Housing/home_before.csv', index_col=0).transpose()
housing_after = pd.read_csv('./Data/Housing/home_after.csv', index_col=0).transpose()
housing_before.head()
total own rent
Toronto 1112905 587080 525825
Ward 1 18305 9925 8385
Ward 2 19465 11705 7765
Ward 3 24530 17615 6915
Ward 4 25675 15700 9975
housing_after.head()
total own rent
Toronto 1112905 587080 525825
Ward 1 37895 20945 16945
Ward 2 45045 30175 14870
Ward 3 59730 33860 25870
Ward 4 50315 21375 28945
housing_before, housing_after = scale_populations(housing_before, housing_after)
housing_before.head()
total own rent
Ward 1 60735.0 32930.613220 27820.976509
Ward 2 57210.0 34402.417159 22822.278448
Ward 3 64065.0 46005.094782 18059.905218
Ward 4 66060.0 40395.014606 25664.985394
Ward 5 49520.0 28338.746890 21192.454196
# Initialize params
total_before = housing_before.total
protected_before = housing_before.rent
majority_before = housing_before.own

total_after = housing_after.total
protected_after = housing_after.rent
majority_after = housing_after.own

protected_increase, majority_increase = get_increases(total_before, protected_before, majority_before, total_after, protected_after, majority_after)
print("If you rent, your ward size increased by {} people on average".format(protected_increase))
print("If you own your home, your ward size increased by {} people on average".format(majority_increase))
print("This is a disparity of {} people on average".format(protected_increase-majority_increase))
If you rent, your ward size increased by 50615 people on average
If you own your home, your ward size increased by 49567 people on average
This is a disparity of 1048 people on average
# lost majorities
prop_protected_before = protected_before / total_before
print("Wards with majority renters before: {}/47={}"
      .format(len([p for p in prop_protected_before if p > threshold]),
             len([p for p in prop_protected_before if p > threshold])/47))

prop_protected_after = protected_after / total_after
print("Wards with majority renters after: {}/25={}"
      .format(len([p for p in prop_protected_after if p > threshold]),
             len([p for p in prop_protected_after if p > threshold])/25))
Wards with majority renters before: 17/47=0.3617021276595745
Wards with majority renters after: 9/25=0.36