Joins and More Plotting

For more information on joins, see: http://geopandas.org/mergingdata.html
For more information on plotting and styling, see: http://geopandas.org/mapping.html

This time, we will build on the census tract dataframes we worked with earlier and join them to a GeoDataFrame.

Start by importing pandas as pd, geopandas as gpd, matplotlib.pyplot as plt, and os

In [2]:
import pandas as pd
import geopandas as gpd
import matplotlib.pyplot as plt
import os

Set your working directory using os to workshopdata/

Type:
>>> os.chdir('../../')

In the next cell, type:
>>> os.getcwd() to view your current directory.

In [3]:
os.chdir('../../')
In [20]:
os.getcwd()
Out[20]:
'/home/jupyter-boaty3'

Import your data.

Use gpd.read_file() to import the following as a variable named TahoeTracts: TahoeTracts.geojson file from the workshopdata folder.

Use pd.read_csv() to import the following as a variable named AllTracts: the All_Counties.csv you produced in the earlier exercise. Should be in your current working directory.

In [21]:
TahoeTracts = gpd.read_file('workshopdata/TahoeTracts.geojson')
In [22]:
AllTracts = pd.read_csv('workshopdata/All_Counties.csv')

View your new TahoeTracts geodataframe and your AllTracts dataframe in the next two cells:

In [23]:
TahoeTracts
Out[23]:
OBJECTID STATEFP COUNTYFP TRACTCE AFFGEOID GEOID NAME LSAD ALAND AWATER ... ShapeSTAre ShapeSTLen POP_2010 POP_2011 POP_2012 POP_2013 POP_2014 POP_2015 POP_2016 geometry
0 5 06 017 031600 1400000US06017031600 06017031600 316 CT 7926181 0 ... 7.910677e+06 12369.248497 4126 3715 4025 4026 4073 3918 3868 POLYGON ((763537.9836551668 4315733.585538371,...
1 7 06 017 030502 1400000US06017030502 06017030502 305.02 CT 17251475 36532 ... 1.729684e+07 26313.490214 2641 2767 2446 2296 2340 2408 2393 POLYGON ((756107.5910784202 4312352.066995064,...
2 8 06 017 030505 1400000US06017030505 06017030505 305.05 CT 148884104 451002 ... 1.494343e+08 64339.455834 2704 1941 2011 2102 2288 2555 2506 POLYGON ((756288.66584861 4293154.567955514, 7...
3 9 06 061 020107 1400000US06061020107 06061020107 201.07 CT 7179614 301151 ... 7.748818e+06 19336.115918 3510 2966 3240 3355 3111 3279 2974 POLYGON ((756205.4678623071 4347378.82132867, ...
4 10 06 061 022100 1400000US06061022100 06061022100 221 CT 59523104 610172 ... 6.015945e+07 38311.939639 961 775 964 915 975 695 712 POLYGON ((737695.3421095964 4329943.931698944,...
5 12 06 061 022300 1400000US06061022300 06061022300 223 CT 26970758 1445828 ... 2.846237e+07 29087.423600 709 774 792 817 738 657 465 POLYGON ((742251.022959603 4326559.309656151, ...
6 15 06 061 020105 1400000US06061020105 06061020105 201.05 CT 27538208 917608 ... 2.847750e+07 26365.178953 1352 1284 1313 1186 1183 1124 910 POLYGON ((746500.9871599386 4345515.946135351,...
7 16 06 017 030401 1400000US06017030401 06017030401 304.01 CT 4779638 541288 ... 5.295395e+06 12169.387676 3498 4117 3921 4204 4185 3874 3727 POLYGON ((758052.428158245 4313674.241877396, ...
8 17 06 017 032000 1400000US06017032000 06017032000 320 CT 185118854 16702898 ... 2.019676e+08 92774.712261 1015 666 681 628 676 667 793 POLYGON ((741888.4049193002 4322404.514040146,...
9 18 06 017 030402 1400000US06017030402 06017030402 304.02 CT 10996508 0 ... 1.097609e+07 18090.954392 3723 3406 3485 3450 3512 3495 3754 POLYGON ((757858.6178901512 4308600.865612617,...
10 19 06 017 030200 1400000US06017030200 06017030200 302 CT 9413520 1486408 ... 1.093229e+07 28157.660122 4773 4985 4866 4971 4774 5122 5085 POLYGON ((758448.6902930085 4314160.021097424,...
11 20 06 061 020104 1400000US06061020104 06061020104 201.04 CT 22784547 718832 ... 2.351870e+07 23358.896988 1288 1115 1221 1049 1140 1198 1025 POLYGON ((743461.9177602548 4342225.382377071,...
12 21 06 017 030504 1400000US06017030504 06017030504 305.04 CT 29841317 0 ... 2.991250e+07 34654.718856 2912 2606 2863 2737 2535 2517 2523 POLYGON ((759783.1446733195 4307185.273145664,...
13 22 06 017 030302 1400000US06017030302 06017030302 303.02 CT 3241412 0 ... 3.222709e+06 7149.954847 2867 2909 3025 2838 2654 2756 2783 POLYGON ((760105.6257202309 4314143.543000136,...
14 23 06 017 030301 1400000US06017030301 06017030301 303.01 CT 1134174 0 ... 1.140877e+06 4804.178212 2469 2726 2332 2004 2195 2184 2279 POLYGON ((760950.4026811561 4312520.682067305,...
15 24 06 061 020106 1400000US06061020106 06061020106 201.06 CT 22134813 359834 ... 2.252008e+07 25390.897387 1719 1546 1470 1722 1605 1708 1549 POLYGON ((751975.3986586956 4349196.49102943, ...
16 25 06 061 022200 1400000US06061022200 06061022200 222 CT 23421449 658426 ... 2.409829e+07 22166.321794 909 1031 1071 981 1080 973 720 POLYGON ((740404.0822636615 4338448.106498918,...
17 27 32 005 001800 1400000US32005001800 32005001800 18 CT 24384403 0 ... 2.446818e+07 25242.736724 2152 1621 1690 2005 2027 1970 2242 POLYGON ((765223.2288777279 4317212.837094843,...
18 28 32 031 003305 1400000US32031003305 32031003305 33.05 CT 1469101 0 ... 1.479779e+06 5721.492317 1247 1328 1203 1312 1367 1340 1323 POLYGON ((761364.9718129067 4349296.307312997,...
19 29 32 031 003307 1400000US32031003307 32031003307 33.07 CT 2162328 172816 ... 2.325449e+06 9127.199582 1231 908 944 1084 1208 1334 1364 POLYGON ((762969.1181488186 4348909.760276634,...
20 34 32 031 003308 1400000US32031003308 32031003308 33.08 CT 18644049 428699 ... 1.886664e+07 34970.534568 2333 1843 1905 2102 2059 2185 2132 POLYGON ((758465.1412903005 4346425.449485622,...
21 35 32 031 003309 1400000US32031003309 32031003309 33.09 CT 42170951 1893955 ... 4.408516e+07 45196.420659 2546 2761 2463 2504 2424 2558 2244 POLYGON ((762546.4514184017 4350313.481245542,...
22 36 32 005 001700 1400000US32005001700 32005001700 17 CT 16602399 607877 ... 1.721655e+07 22213.329012 1601 1622 1563 1722 1762 2009 1894 POLYGON ((763458.5283682477 4319809.30606739, ...
23 38 32 005 001600 1400000US32005001600 32005001600 16 CT 57708530 2026394 ... 5.975450e+07 46059.467058 1591 793 990 1006 1155 1173 1137 POLYGON ((762784.7934791641 4333177.226866653,...
24 40 32 031 003306 1400000US32031003306 32031003306 33.06 CT 1426175 148536 ... 1.565794e+06 7213.022986 1730 1507 1612 1652 1524 1556 1713 POLYGON ((761063.3437625626 4349017.165558951,...

25 rows × 21 columns

In [24]:
AllTracts
Out[24]:
GEOID Name of Area Qualifying Name State/U.S.-Abbreviation (USPS) Summary Level Geographic Component File Identification Logical Record Number US Region ... Median Household Income (In 2017 Inflation Adjusted Dollars) Housing Units Occupied Housing Units: Occupied Housing Units: Owner Occupied Occupied Housing Units: Renter Occupied Population for Whom Poverty Status Is Determined: Population for Whom Poverty Status Is Determined: Under 1.00 (Doing Poorly) Population for Whom Poverty Status Is Determined: 1.00 to 1.99 (Struggling) Population for Whom Poverty Status Is Determined: Under 2.00 (Poor or Struggling) Population for Whom Poverty Status Is Determined: 2.00 and Over (Doing Ok)
0 32005001000 Census Tract 10, Douglas County, Nevada Census Tract 10, Douglas County, Nevada nv 140 0 ACSSF 818 NaN NaN ... 67805.0 1139 1034 863 171 2520 125 249 374 2146
1 32005001100 Census Tract 11, Douglas County, Nevada Census Tract 11, Douglas County, Nevada nv 140 0 ACSSF 819 NaN NaN ... 54907.0 2223 2198 1124 1074 5589 492 1174 1666 3923
2 32005001200 Census Tract 12, Douglas County, Nevada Census Tract 12, Douglas County, Nevada nv 140 0 ACSSF 820 NaN NaN ... 48029.0 1409 1322 759 563 2889 371 441 812 2077
3 32005001300 Census Tract 13, Douglas County, Nevada Census Tract 13, Douglas County, Nevada nv 140 0 ACSSF 821 NaN NaN ... 73854.0 879 757 700 57 1725 175 236 411 1314
4 32005001400 Census Tract 14, Douglas County, Nevada Census Tract 14, Douglas County, Nevada nv 140 0 ACSSF 822 NaN NaN ... 54605.0 1624 1455 908 547 3085 389 316 705 2380
5 32005001500 Census Tract 15, Douglas County, Nevada Census Tract 15, Douglas County, Nevada nv 140 0 ACSSF 823 NaN NaN ... 47435.0 2730 2669 1382 1287 5885 818 1433 2251 3634
6 32005001600 Census Tract 16, Douglas County, Nevada Census Tract 16, Douglas County, Nevada nv 140 0 ACSSF 824 NaN NaN ... 81750.0 1727 635 499 136 1221 82 58 140 1081
7 32005001700 Census Tract 17, Douglas County, Nevada Census Tract 17, Douglas County, Nevada nv 140 0 ACSSF 825 NaN NaN ... 50655.0 1281 778 282 496 1730 169 337 506 1224
8 32005001800 Census Tract 18, Douglas County, Nevada Census Tract 18, Douglas County, Nevada nv 140 0 ACSSF 826 NaN NaN ... 58913.0 1807 1104 753 351 2303 188 422 610 1693
9 32005001900 Census Tract 19, Douglas County, Nevada Census Tract 19, Douglas County, Nevada nv 140 0 ACSSF 827 NaN NaN ... 135764.0 849 526 437 89 1322 35 138 173 1149
10 32005002000 Census Tract 20, Douglas County, Nevada Census Tract 20, Douglas County, Nevada nv 140 0 ACSSF 828 NaN NaN ... 57325.0 1350 1317 956 361 3367 460 631 1091 2276
11 32005002100 Census Tract 21, Douglas County, Nevada Census Tract 21, Douglas County, Nevada nv 140 0 ACSSF 829 NaN NaN ... 71653.0 869 869 628 241 2150 98 139 237 1913
12 32005002200 Census Tract 22, Douglas County, Nevada Census Tract 22, Douglas County, Nevada nv 140 0 ACSSF 830 NaN NaN ... 81441.0 2772 2688 2408 280 6379 287 691 978 5401
13 32005002300 Census Tract 23, Douglas County, Nevada Census Tract 23, Douglas County, Nevada nv 140 0 ACSSF 831 NaN NaN ... 87375.0 1637 1473 1257 216 3515 210 325 535 2980
14 32005002400 Census Tract 24, Douglas County, Nevada Census Tract 24, Douglas County, Nevada nv 140 0 ACSSF 832 NaN NaN ... 43021.0 763 687 503 184 1814 494 383 877 937
15 32005002500 Census Tract 25, Douglas County, Nevada Census Tract 25, Douglas County, Nevada nv 140 0 ACSSF 833 NaN NaN ... 46481.0 1004 864 684 180 1804 254 431 685 1119
16 32005990000 Census Tract 9900, Douglas County, Nevada Census Tract 9900, Douglas County, Nevada nv 140 0 ACSSF 834 NaN NaN ... NaN 0 0 0 0 0 0 0 0 0
17 32031000101 Census Tract 1.01, Washoe County, Nevada Census Tract 1.01, Washoe County, Nevada nv 140 0 ACSSF 882 NaN NaN ... 27213.0 2582 2185 432 1753 3113 972 680 1652 1461
18 32031000102 Census Tract 1.02, Washoe County, Nevada Census Tract 1.02, Washoe County, Nevada nv 140 0 ACSSF 883 NaN NaN ... 18539.0 2186 1630 83 1547 2755 1168 862 2030 725
19 32031000201 Census Tract 2.01, Washoe County, Nevada Census Tract 2.01, Washoe County, Nevada nv 140 0 ACSSF 884 NaN NaN ... 27739.0 1383 1241 406 835 3263 1004 1128 2132 1131
20 32031000202 Census Tract 2.02, Washoe County, Nevada Census Tract 2.02, Washoe County, Nevada nv 140 0 ACSSF 885 NaN NaN ... 25607.0 1674 1521 65 1456 2922 858 883 1741 1181
21 32031000300 Census Tract 3, Washoe County, Nevada Census Tract 3, Washoe County, Nevada nv 140 0 ACSSF 886 NaN NaN ... 36361.0 2313 2255 549 1706 3596 480 961 1441 2155
22 32031000400 Census Tract 4, Washoe County, Nevada Census Tract 4, Washoe County, Nevada nv 140 0 ACSSF 887 NaN NaN ... 63836.0 2731 2581 1547 1034 5309 564 471 1035 4274
23 32031000700 Census Tract 7, Washoe County, Nevada Census Tract 7, Washoe County, Nevada nv 140 0 ACSSF 888 NaN NaN ... 35476.0 2910 2587 709 1878 5131 847 1615 2462 2669
24 32031000900 Census Tract 9, Washoe County, Nevada Census Tract 9, Washoe County, Nevada nv 140 0 ACSSF 889 NaN NaN ... 27420.0 2071 1761 236 1525 4590 1437 1869 3306 1284
25 32031001005 Census Tract 10.05, Washoe County, Nevada Census Tract 10.05, Washoe County, Nevada nv 140 0 ACSSF 890 NaN NaN ... 45878.0 1543 1401 663 738 2755 368 677 1045 1710
26 32031001008 Census Tract 10.08, Washoe County, Nevada Census Tract 10.08, Washoe County, Nevada nv 140 0 ACSSF 891 NaN NaN ... 27229.0 2186 1995 63 1932 4416 1293 1922 3215 1201
27 32031001009 Census Tract 10.09, Washoe County, Nevada Census Tract 10.09, Washoe County, Nevada nv 140 0 ACSSF 892 NaN NaN ... 31429.0 1652 1494 324 1170 2920 594 735 1329 1591
28 32031001010 Census Tract 10.10, Washoe County, Nevada Census Tract 10.10, Washoe County, Nevada nv 140 0 ACSSF 893 NaN NaN ... 93125.0 1279 1238 996 242 2858 145 328 473 2385
29 32031001011 Census Tract 10.11, Washoe County, Nevada Census Tract 10.11, Washoe County, Nevada nv 140 0 ACSSF 894 NaN NaN ... 125577.0 1462 1370 1254 116 3648 182 234 416 3232
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
227 6061021502 Census Tract 215.02, Placer County, California Census Tract 215.02, Placer County, California ca 140 0 ACSSF 7169 NaN NaN ... 85393.0 1559 1479 1124 355 3665 226 455 681 2984
228 6061021603 Census Tract 216.03, Placer County, California Census Tract 216.03, Placer County, California ca 140 0 ACSSF 7170 NaN NaN ... 37756.0 2096 1902 766 1136 4438 940 992 1932 2506
229 6061021604 Census Tract 216.04, Placer County, California Census Tract 216.04, Placer County, California ca 140 0 ACSSF 7171 NaN NaN ... 99943.0 1410 1287 1166 121 4166 532 383 915 3251
230 6061021801 Census Tract 218.01, Placer County, California Census Tract 218.01, Placer County, California ca 140 0 ACSSF 7172 NaN NaN ... 93036.0 1960 1867 1755 112 4909 339 530 869 4040
231 6061021802 Census Tract 218.02, Placer County, California Census Tract 218.02, Placer County, California ca 140 0 ACSSF 7173 NaN NaN ... 56088.0 2656 2429 1756 673 6068 733 1334 2067 4001
232 6061021901 Census Tract 219.01, Placer County, California Census Tract 219.01, Placer County, California ca 140 0 ACSSF 7174 NaN NaN ... 64205.0 1366 1230 868 362 2598 165 420 585 2013
233 6061021902 Census Tract 219.02, Placer County, California Census Tract 219.02, Placer County, California ca 140 0 ACSSF 7175 NaN NaN ... 78281.0 1964 1887 1760 127 4774 270 784 1054 3720
234 6061022002 Census Tract 220.02, Placer County, California Census Tract 220.02, Placer County, California ca 140 0 ACSSF 7176 NaN NaN ... 56307.0 3070 2758 1903 855 7322 1045 1543 2588 4734
235 6061022011 Census Tract 220.11, Placer County, California Census Tract 220.11, Placer County, California ca 140 0 ACSSF 7177 NaN NaN ... 97857.0 2980 676 455 221 1576 92 113 205 1371
236 6061022013 Census Tract 220.13, Placer County, California Census Tract 220.13, Placer County, California ca 140 0 ACSSF 7178 NaN NaN ... 61250.0 1564 1006 791 215 2372 333 297 630 1742
237 6061022014 Census Tract 220.14, Placer County, California Census Tract 220.14, Placer County, California ca 140 0 ACSSF 7179 NaN NaN ... 70268.0 3163 511 359 152 1101 68 136 204 897
238 6061022100 Census Tract 221, Placer County, California Census Tract 221, Placer County, California ca 140 0 ACSSF 7180 NaN NaN ... 80859.0 1413 293 249 44 613 24 82 106 507
239 6061022200 Census Tract 222, Placer County, California Census Tract 222, Placer County, California ca 140 0 ACSSF 7181 NaN NaN ... 73795.0 1329 293 205 88 756 96 89 185 571
240 6061022300 Census Tract 223, Placer County, California Census Tract 223, Placer County, California ca 140 0 ACSSF 7182 NaN NaN ... 60521.0 1554 199 186 13 372 89 18 107 265
241 6061022400 Census Tract 224, Placer County, California Census Tract 224, Placer County, California ca 140 0 ACSSF 7183 NaN NaN ... 105526.0 1804 1746 1049 697 4780 350 471 821 3959
242 6061022500 Census Tract 225, Placer County, California Census Tract 225, Placer County, California ca 140 0 ACSSF 7184 NaN NaN ... 158607.0 1869 1745 1605 140 5981 157 338 495 5486
243 6061022600 Census Tract 226, Placer County, California Census Tract 226, Placer County, California ca 140 0 ACSSF 7185 NaN NaN ... 73504.0 2013 1911 793 1118 5107 545 683 1228 3879
244 6061022800 Census Tract 228, Placer County, California Census Tract 228, Placer County, California ca 140 0 ACSSF 7186 NaN NaN ... 92431.0 1656 1585 944 641 4666 260 310 570 4096
245 6061022900 Census Tract 229, Placer County, California Census Tract 229, Placer County, California ca 140 0 ACSSF 7187 NaN NaN ... 79556.0 1706 1698 847 851 5124 385 487 872 4252
246 6061023000 Census Tract 230, Placer County, California Census Tract 230, Placer County, California ca 140 0 ACSSF 7188 NaN NaN ... 111103.0 999 968 807 161 3254 93 97 190 3064
247 6061023100 Census Tract 231, Placer County, California Census Tract 231, Placer County, California ca 140 0 ACSSF 7189 NaN NaN ... 129531.0 2771 2654 1998 656 8312 254 457 711 7601
248 6061023200 Census Tract 232, Placer County, California Census Tract 232, Placer County, California ca 140 0 ACSSF 7190 NaN NaN ... 97798.0 1753 1675 1356 319 5573 307 310 617 4956
249 6061023300 Census Tract 233, Placer County, California Census Tract 233, Placer County, California ca 140 0 ACSSF 7191 NaN NaN ... 96442.0 1604 1604 1293 311 5318 373 282 655 4663
250 6061023400 Census Tract 234, Placer County, California Census Tract 234, Placer County, California ca 140 0 ACSSF 7192 NaN NaN ... 82396.0 1662 1619 1210 409 5007 333 728 1061 3946
251 6061023500 Census Tract 235, Placer County, California Census Tract 235, Placer County, California ca 140 0 ACSSF 7193 NaN NaN ... 133080.0 1766 1732 1560 172 6044 184 136 320 5724
252 6061023600 Census Tract 236, Placer County, California Census Tract 236, Placer County, California ca 140 0 ACSSF 7194 NaN NaN ... 67179.0 2655 2568 2261 307 4136 132 454 586 3550
253 6061023700 Census Tract 237, Placer County, California Census Tract 237, Placer County, California ca 140 0 ACSSF 7195 NaN NaN ... 61121.0 2056 2014 1764 250 3416 183 392 575 2841
254 6061023800 Census Tract 238, Placer County, California Census Tract 238, Placer County, California ca 140 0 ACSSF 7196 NaN NaN ... 61111.0 1957 1836 1598 238 3146 276 282 558 2588
255 6061023900 Census Tract 239, Placer County, California Census Tract 239, Placer County, California ca 140 0 ACSSF 7197 NaN NaN ... 104946.0 1031 1021 827 194 3258 263 154 417 2841
256 6061990000 Census Tract 9900, Placer County, California Census Tract 9900, Placer County, California ca 140 0 ACSSF 7198 NaN NaN ... NaN 0 0 0 0 0 0 0 0 0

257 rows × 104 columns

We will now perform a table join and add the attributes from AllTracts to TahoeTracts. We will join on the 'GEOID' columns.

But...

Look closely at the AllTracts GEOID column. Notice anything?

type:
>>> AllTracts.GEOID

In [25]:
AllTracts.GEOID
Out[25]:
0      32005001000
1      32005001100
2      32005001200
3      32005001300
4      32005001400
          ...     
252     6061023600
253     6061023700
254     6061023800
255     6061023900
256     6061990000
Name: GEOID, Length: 257, dtype: int64

Arrgghh! Classic problem: leading zeros have been stripped. WHY?!?!?!

Fix it! Reimport the All_Counites.csv file to the same variable, but this time we'll tell pandas the 'GEOID' column should be read as a string.

Type:
*>>> AllTracts = pd.read_csv('All_Counties.csv', DTYPE = {"GEOID":str})

In [27]:
AllTracts = pd.read_csv('workshopdata/All_Counties.csv', dtype={"GEOID":str})

Check the results by Typing: AllTracts.GEOID

In [28]:
AllTracts.GEOID
Out[28]:
0      32005001000
1      32005001100
2      32005001200
3      32005001300
4      32005001400
          ...     
252    06061023600
253    06061023700
254    06061023800
255    06061023900
256    06061990000
Name: GEOID, Length: 257, dtype: object

Hell Yes!

Next, let's join AllTracts to TahoeTracts, dropping what we don't need from the AllTracts.

Note: TahoeTracts only consists of the census tracts around Lake Tahoe and that there are 25 tracts, but AllTracts represents all the tracts within each county bordering the lake: 257 tracts in total.

Type:
>>> TahoeTracts = TahoeTracts.merge(AllTracts, on='GEOID')

In [29]:
TahoeTracts = TahoeTracts.merge(AllTracts, on = 'GEOID')

Ya did it.

View the results by typing:
>>> TahoeTracts

In [30]:
TahoeTracts
Out[30]:
OBJECTID STATEFP COUNTYFP TRACTCE AFFGEOID GEOID NAME LSAD ALAND AWATER ... Median Household Income (In 2017 Inflation Adjusted Dollars) Housing Units Occupied Housing Units: Occupied Housing Units: Owner Occupied Occupied Housing Units: Renter Occupied Population for Whom Poverty Status Is Determined: Population for Whom Poverty Status Is Determined: Under 1.00 (Doing Poorly) Population for Whom Poverty Status Is Determined: 1.00 to 1.99 (Struggling) Population for Whom Poverty Status Is Determined: Under 2.00 (Poor or Struggling) Population for Whom Poverty Status Is Determined: 2.00 and Over (Doing Ok)
0 5 06 017 031600 1400000US06017031600 06017031600 316 CT 7926181 0 ... 36014.0 3366 1318 234 1084 3017 731 889 1620 1397
1 7 06 017 030502 1400000US06017030502 06017030502 305.02 CT 17251475 36532 ... 89583.0 1889 1027 932 95 2624 152 295 447 2177
2 8 06 017 030505 1400000US06017030505 06017030505 305.05 CT 148884104 451002 ... 63194.0 2102 921 682 239 2336 129 320 449 1887
3 9 06 061 020107 1400000US06061020107 06061020107 201.07 CT 7179614 301151 ... 43793.0 1973 1026 468 558 2614 322 768 1090 1524
4 10 06 061 022100 1400000US06061022100 06061022100 221 CT 59523104 610172 ... 80859.0 1413 293 249 44 613 24 82 106 507
5 12 06 061 022300 1400000US06061022300 06061022300 223 CT 26970758 1445828 ... 60521.0 1554 199 186 13 372 89 18 107 265
6 15 06 061 020105 1400000US06061020105 06061020105 201.05 CT 27538208 917608 ... 63958.0 2019 486 361 125 965 195 45 240 725
7 16 06 017 030401 1400000US06017030401 06017030401 304.01 CT 4779638 541288 ... 56339.0 3730 1551 1115 436 3692 323 557 880 2812
8 17 06 017 032000 1400000US06017032000 06017032000 320 CT 185118854 16702898 ... 77917.0 2786 256 202 54 596 27 25 52 544
9 18 06 017 030402 1400000US06017030402 06017030402 304.02 CT 10996508 0 ... 37868.0 2862 1664 756 908 3919 743 952 1695 2224
10 19 06 017 030200 1400000US06017030200 06017030200 302 CT 9413520 1486408 ... 54071.0 3386 2055 946 1109 5103 519 1110 1629 3474
11 20 06 061 020104 1400000US06061020104 06061020104 201.04 CT 22784547 718832 ... 70392.0 2064 518 332 186 979 206 76 282 697
12 21 06 017 030504 1400000US06017030504 06017030504 305.04 CT 29841317 0 ... 70435.0 2144 926 692 234 2433 230 346 576 1857
13 22 06 017 030302 1400000US06017030302 06017030302 303.02 CT 3241412 0 ... 36782.0 2504 1207 478 729 2718 529 793 1322 1396
14 23 06 017 030301 1400000US06017030301 06017030301 303.01 CT 1134174 0 ... 48269.0 1852 1054 543 511 2874 479 841 1320 1554
15 24 06 061 020106 1400000US06061020106 06061020106 201.06 CT 22134813 359834 ... 57262.0 1956 562 360 202 1488 122 268 390 1098
16 25 06 061 022200 1400000US06061022200 06061022200 222 CT 23421449 658426 ... 73795.0 1329 293 205 88 756 96 89 185 571
17 27 32 005 001800 1400000US32005001800 32005001800 18 CT 24384403 0 ... 58913.0 1807 1104 753 351 2303 188 422 610 1693
18 28 32 031 003305 1400000US32031003305 32031003305 33.05 CT 1469101 0 ... 65417.0 835 510 335 175 1293 114 139 253 1040
19 29 32 031 003307 1400000US32031003307 32031003307 33.07 CT 2162328 172816 ... 74545.0 1229 506 311 195 1120 156 190 346 774
20 34 32 031 003308 1400000US32031003308 32031003308 33.08 CT 18644049 428699 ... 104313.0 1959 975 850 125 2073 119 95 214 1859
21 35 32 031 003309 1400000US32031003309 32031003309 33.09 CT 42170951 1893955 ... 93070.0 2621 1071 899 172 2287 106 156 262 2025
22 36 32 005 001700 1400000US32005001700 32005001700 17 CT 16602399 607877 ... 50655.0 1281 778 282 496 1730 169 337 506 1224
23 38 32 005 001600 1400000US32005001600 32005001600 16 CT 57708530 2026394 ... 81750.0 1727 635 499 136 1221 82 58 140 1081
24 40 32 031 003306 1400000US32031003306 32031003306 33.06 CT 1426175 148536 ... 66563.0 1350 691 337 354 1968 418 231 649 1319

25 rows × 124 columns

Great! You've added over a hundred columns. This is the same as a "join" in ArcGIS.

Let's export this because we will use this file again later.

Type:
>>> TahoeTracts.to_file('TahoeTracts_geodata.geojson', driver = 'GeoJSON')

In [31]:
TahoeTracts.to_file('TahoeTracts_geodata.geojson', driver = 'GeoJSON')

Now let's work on plotting.

Plot it! Type:
>>> TahoeTracts.plot()

In [32]:
TahoeTracts.plot()
Out[32]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f36c6ce2048>

Now try making a choropleth

First, Type:
>>> list(TahoeTracts) to list all of the column headers

In [33]:
list(TahoeTracts)
Out[33]:
['OBJECTID',
 'STATEFP',
 'COUNTYFP',
 'TRACTCE',
 'AFFGEOID',
 'GEOID',
 'NAME',
 'LSAD',
 'ALAND',
 'AWATER',
 'County_x',
 'ShapeSTAre',
 'ShapeSTLen',
 'POP_2010',
 'POP_2011',
 'POP_2012',
 'POP_2013',
 'POP_2014',
 'POP_2015',
 'POP_2016',
 'geometry',
 'Name of Area',
 'Qualifying Name',
 'State/U.S.-Abbreviation (USPS)',
 'Summary Level',
 'Geographic Component',
 'File Identification',
 'Logical Record Number',
 'US',
 'Region',
 'Division',
 'State (Census Code)',
 'State (FIPS)',
 'County_y',
 'County Subdivision (FIPS)',
 'Place (FIPS Code)',
 'Place (State FIPS + Place FIPS)',
 'Census Tract',
 'Block Group',
 'Consolidated City',
 'American Indian Area/Alaska Native Area/Hawaiian Home Land (Census)',
 'American Indian Area/Alaska Native Area/Hawaiian Home Land (FIPS)',
 'American Indian Trust Land/Hawaiian Home Land Indicator',
 'American Indian Tribal Subdivision (Census)',
 'American Indian Tribal Subdivision (FIPS)',
 'Alaska Native Regional Corporation (FIPS)',
 'Metropolitan and Micropolitan Statistical Area',
 'Combined Statistical Area',
 'Metropolitan Division',
 'Metropolitan Area Central City',
 'Metropolitan/Micropolitan Indicator Flag',
 'New England City and Town Combined Statistical Area',
 'New England City and Town Area',
 'New England City and Town Area Division',
 'Urban Area',
 'Urban Area Central Place',
 'Current Congressional District ***',
 'State Legislative District Upper',
 'State Legislative District Lower',
 'Voting District',
 'ZIP Code Tabulation Area (3-digit)',
 'ZIP Code Tabulation Area (5-digit)',
 'Subbarrio (FIPS)',
 'School District (Elementary)',
 'School District (Secondary)',
 'School District (Unified)',
 'Urban/Rural',
 'Principal City Indicator',
 'Traffic Analysis Zone',
 'Urban Growth Area',
 'Public Use Microdata Area - 5% File',
 'Public Use Microdata Area - 1% File',
 'Geographic Identifier',
 'Tribal Tract',
 'Tribal Block Group',
 'Area (Land)',
 'Area (Water)',
 'Total Population',
 'Total Population.1',
 'Population Density (Per Sq. Mile)',
 'Area (Land).1',
 'Total Population:',
 'Total Population: Male',
 'Total Population: Female',
 'Total Population:.1',
 'Total Population: Under 5 Years',
 'Total Population: 5 to 9 Years',
 'Total Population: 10 to 14 Years',
 'Total Population: 15 to 17 Years',
 'Total Population: 18 to 24 Years',
 'Total Population: 25 to 34 Years',
 'Total Population: 35 to 44 Years',
 'Total Population: 45 to 54 Years',
 'Total Population: 55 to 64 Years',
 'Total Population: 65 to 74 Years',
 'Total Population: 75 to 84 Years',
 'Total Population: 85 Years and Over',
 'Total Population:.2',
 'Total Population: White Alone',
 'Total Population: Black or African American Alone',
 'Total Population: American Indian and Alaska Native Alone',
 'Total Population: Asian Alone',
 'Total Population: Native Hawaiian and Other Pacific Islander Alone',
 'Total Population: Some Other Race Alone',
 'Total Population: Two or More Races',
 'Households:',
 'Households: Family Households',
 'Households: Family Households: Married-Couple Family',
 'Households: Family Households: Other Family',
 'Households: Family Households: Other Family: Male Householder, No Wife Present',
 'Households: Family Households: Other Family: Female Householder, No Husband Present',
 'Households: Nonfamily Households',
 'Households: Nonfamily Households: Male Householder',
 'Households: Nonfamily Households: Female Householder',
 'Median Household Income (In 2017 Inflation Adjusted Dollars)',
 'Housing Units',
 'Occupied Housing Units:',
 'Occupied Housing Units: Owner Occupied',
 'Occupied Housing Units: Renter Occupied',
 'Population for Whom Poverty Status Is Determined:',
 'Population for Whom Poverty Status Is Determined: Under 1.00 (Doing Poorly)',
 'Population for Whom Poverty Status Is Determined: 1.00 to 1.99 (Struggling)',
 'Population for Whom Poverty Status Is Determined: Under 2.00 (Poor or Struggling)',
 'Population for Whom Poverty Status Is Determined: 2.00 and Over (Doing Ok)']

Next,

Type:
>>> TahoeTracts.plot('a column name')

In [34]:
TahoeTracts.plot('Median Household Income (In 2017 Inflation Adjusted Dollars)')
Out[34]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f36c6bf6400>

Add a legend

Type:
>>> TahoeTracts.plot('Median Household Income (In 2017 Inflation Adjusted Dollars)', legend=True)

In [35]:
TahoeTracts.plot('Median Household Income (In 2017 Inflation Adjusted Dollars)', legend = True)
Out[35]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f36c67757b8>

Change the figure size

Type:
>>> TahoeTracts.plot('Median Household Income (In 2017 Inflation Adjusted Dollars)', legend=True, figsize = (8,8))

In [36]:
TahoeTracts.plot('Median Household Income (In 2017 Inflation Adjusted Dollars)', legend = True, figsize = (8,8))
Out[36]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f36c463d940>

Next, modify the color scheme

Type:
>>>TahoeTracts.plot('Median Household Income (In 2017 Inflation Adjusted Dollars)', legend=True, figsize = (8,8), cmap='OrRd')

In [37]:
TahoeTracts.plot('Median Household Income (In 2017 Inflation Adjusted Dollars)', 
                 legend = True, 
                 figsize = (8,8), 
                 cmap='OrRd'
                )
Out[37]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f36c45b4b00>

You love this beautiful map! So Save it as an image!

Past your code form the previous cell into the cell below. Press enter to add a second line, then Type:
>>> plt.savefig('TahoeMHHI.png')

In [39]:
TahoeTracts.plot('Median Household Income (In 2017 Inflation Adjusted Dollars)', 
                 legend = True, 
                 figsize = (8,8), 
                 cmap='OrRd'
                )

plt.savefig('TahoeMHHI.png')

Done! Open up yor data folder and double click on TahoeMHHI.png to view

Bonus! Want to add another layer?

Add a points of interest layer:

Type:
>>> POIs = gpd.read_file('workshopdata/Tahoe_POIs.geojson)

In [40]:
POIs = gpd.read_file('workshopdata/Tahoe_POIs.geojson')

Now, as before, use TahoeTracts.plot(), but you will make it a variable named 'basemap'

In the next cell, first type:
>>> basemap = TahoeTracts.plot()

Then, plot the 'POIs' layer and pass 'ax = basemap' as the only arguement (that is, put it in the parentheses)

In a new line in the same cell, type:
>>> POIs.plot(ax = basemap)

In [45]:
basemap = TahoeTracts.plot()

POIs.plot(ax = basemap)
Out[45]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f36c43b16d8>
In [1]:
#### Hey, what the heck?! I thought this was supposed to work.

## Time for you to troubleshoot. What do you think the problem is? How might you fix it?
In [42]:
TahoeTracts.crs
Out[42]:
{'init': 'epsg:26910'}
In [43]:
POIs.crs
Out[43]:
{'init': 'epsg:4326'}
In [44]:
TahoeTracts = TahoeTracts.to_crs(epsg = 4326)

You have two layers displayed, but now let's sytle them

Past the above code into the next cell, but add styling parameters to TahoeTracts:

Modify 'basemap' adding color='white', edgecolor='blue', figsize = (8,8) into the TahoeTracts.plot() parentheses

for POIs.plot(), add color = 'red' into POIS.plot() parentheses

In [48]:
basemap = TahoeTracts.plot(color = 'white', 
                           edgecolor='blue', 
                           figsize=(8,8))

POIs.plot(ax = basemap, color = 'red')
Out[48]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f36c431aeb8>