Lecture 28 – Maps

Data 94, Spring 2021

In [1]:
from datascience import *
import numpy as np

Table.interactive_plots()

Review: scatter plots and line plots

In [2]:
wm = Table.read_table('data/walmart.csv').select('STREETADDR', 'STRCITY', 'STRSTATE', 'type_store', 'LAT', 'LON', 'YEAR')
wm
Out[2]:
STREETADDR STRCITY STRSTATE type_store LAT LON YEAR
2110 WEST WALNUT Rogers AR Supercenter 36.3422 -94.0714 1962
1417 HWY 62/65 N Harrison AR Supercenter 36.237 -93.0935 1964
2901 HWY 412 EAST Siloam Springs AR Supercenter 36.1799 -94.5021 1965
1621 NORTH BUSINESS 9 Morrilton AR Supercenter 35.1565 -92.7586 1967
3801 CAMP ROBINSON RD. North Little Rock AR Wal-Mart 34.8133 -92.3023 1967
2020 SOUTH MUSKOGEE Tahlequah OK Supercenter 35.9237 -94.9719 1968
2705 GRAND AVE Carthage MO Supercenter 37.169 -94.3116 1968
1500 LYNN RIGGS BLVD Claremore OK Supercenter 36.3271 -95.6119 1968
65 WAL-MART DRIVE Mountain Home AR Supercenter 36.329 -92.3578 1968
1303 SOUTH MAIN Sikeston MO Supercenter 36.8912 -89.5836 1968

... (2982 rows omitted)

In [3]:
wm.group('YEAR')
Out[3]:
YEAR count
1962 1
1964 1
1965 1
1967 2
1968 5
1969 5
1970 5
1971 15
1972 17
1973 19

... (33 rows omitted)

In [4]:
wm.group('YEAR').plot('YEAR',
                     title = 'Number of Walmarts Opened Per Year')
In [5]:
wm_per_year = wm.group('YEAR')
wm_per_year = wm_per_year.with_columns(
    'total', np.cumsum(wm_per_year.column('count'))
)
wm_per_year
Out[5]:
YEAR count total
1962 1 1
1964 1 2
1965 1 3
1967 2 5
1968 5 10
1969 5 15
1970 5 20
1971 15 35
1972 17 52
1973 19 71

... (33 rows omitted)

In [6]:
wm_per_year.plot('YEAR', 'total',
                title = 'Total Number of Walmarts Over Time')

Maps with circles

In [7]:
wm_ca = wm.where('STRSTATE', 'CA')
wm_ca
Out[7]:
STREETADDR STRCITY STRSTATE type_store LAT LON YEAR
44765 VALLEY CENTRAL WAY Lancaster CA Wal-Mart 34.7289 -118.327 1990
2150 NO. WATERMAN AVENUE El Centro CA Supercenter 32.7834 -115.577 1990
2225 PLAZA PARKWAY Modesto CA Wal-Mart 37.6718 -121.012 1990
3223 EAST HAMMER LANE Stockton CA Supercenter 38.0389 -121.242 1991
2300 WHITE LANE Bakersfield CA Wal-Mart 35.3442 -119.022 1991
355 ORO DAM BLVD Oroville CA Wal-Mart 39.5586 -121.589 1991
1977 WEST CLEVELAND AVE Madera CA Wal-Mart 36.9148 -120.158 1991
15272 BEAR VALLEY ROAD Victorville CA Wal-Mart 34.4895 -117.353 1991
911 SOUTH CHINA LAKE BLVD Ridgecrest CA Wal-Mart 35.5992 -117.681 1991
1025 SOUTH MAIN Red Bluff CA Wal-Mart 40.1838 -122.241 1991

... (149 rows omitted)

In [8]:
wm_ca.select('LAT', 'LON')
Out[8]:
LAT LON
34.7289 -118.327
32.7834 -115.577
37.6718 -121.012
38.0389 -121.242
35.3442 -119.022
39.5586 -121.589
36.9148 -120.158
34.4895 -117.353
35.5992 -117.681
40.1838 -122.241

... (149 rows omitted)

In [9]:
Circle.map_table(wm_ca.select('LAT', 'LON'))
Out[9]:
Make this Notebook Trusted to load map: File -> Trust Notebook

Modifying circle appearance

In [10]:
Circle.map_table(wm_ca.select('LAT', 'LON'),
                 area = 200,
                 weight = 1.5, 
                 line_color = 'gold',
                 color = 'purple', 
                 fill_opacity = 0.8
                 )
Out[10]:
Make this Notebook Trusted to load map: File -> Trust Notebook

labels

In [11]:
wm_ca.select('LAT', 'LON', 'STREETADDR')
Out[11]:
LAT LON STREETADDR
34.7289 -118.327 44765 VALLEY CENTRAL WAY
32.7834 -115.577 2150 NO. WATERMAN AVENUE
37.6718 -121.012 2225 PLAZA PARKWAY
38.0389 -121.242 3223 EAST HAMMER LANE
35.3442 -119.022 2300 WHITE LANE
39.5586 -121.589 355 ORO DAM BLVD
36.9148 -120.158 1977 WEST CLEVELAND AVE
34.4895 -117.353 15272 BEAR VALLEY ROAD
35.5992 -117.681 911 SOUTH CHINA LAKE BLVD
40.1838 -122.241 1025 SOUTH MAIN

... (149 rows omitted)

In [12]:
wm_ca_labeled = wm_ca.select('LAT', 'LON', 'STREETADDR').relabeled('STREETADDR', 'labels')
wm_ca_labeled
Out[12]:
LAT LON labels
34.7289 -118.327 44765 VALLEY CENTRAL WAY
32.7834 -115.577 2150 NO. WATERMAN AVENUE
37.6718 -121.012 2225 PLAZA PARKWAY
38.0389 -121.242 3223 EAST HAMMER LANE
35.3442 -119.022 2300 WHITE LANE
39.5586 -121.589 355 ORO DAM BLVD
36.9148 -120.158 1977 WEST CLEVELAND AVE
34.4895 -117.353 15272 BEAR VALLEY ROAD
35.5992 -117.681 911 SOUTH CHINA LAKE BLVD
40.1838 -122.241 1025 SOUTH MAIN

... (149 rows omitted)

In [13]:
Circle.map_table(wm_ca_labeled)
Out[13]:
Make this Notebook Trusted to load map: File -> Trust Notebook

color_scale

In [14]:
wm_ca_scales = wm_ca.select('LAT', 'LON', 'STRCITY', 'YEAR') \
                    .relabeled(['STRCITY', 'YEAR'], ['labels', 'color_scale'])

wm_ca_scales
Out[14]:
LAT LON labels color_scale
34.7289 -118.327 Lancaster 1990
32.7834 -115.577 El Centro 1990
37.6718 -121.012 Modesto 1990
38.0389 -121.242 Stockton 1991
35.3442 -119.022 Bakersfield 1991
39.5586 -121.589 Oroville 1991
36.9148 -120.158 Madera 1991
34.4895 -117.353 Victorville 1991
35.5992 -117.681 Ridgecrest 1991
40.1838 -122.241 Red Bluff 1991

... (149 rows omitted)

In [15]:
Circle.map_table(wm_ca_scales,
                fill_opacity = 0.8,
                line_color = None,
                area = 200)
Out[15]:
Make this Notebook Trusted to load map: File -> Trust Notebook

The map above confirms the claims of this LA Times article from 1990, which says:

The company plans to open 10 stores in California in 1990 and 1991, with most to be located in the interior sections of the state. This year, it will open stores in Lancaster, Victorville, El Centro, Madera, Modesto, Ridgecrest and Stockton. In 1991, it plans stores in Elk Grove, Hanford and Bakersfield.

colors

In [16]:
wm_ca
Out[16]:
STREETADDR STRCITY STRSTATE type_store LAT LON YEAR
44765 VALLEY CENTRAL WAY Lancaster CA Wal-Mart 34.7289 -118.327 1990
2150 NO. WATERMAN AVENUE El Centro CA Supercenter 32.7834 -115.577 1990
2225 PLAZA PARKWAY Modesto CA Wal-Mart 37.6718 -121.012 1990
3223 EAST HAMMER LANE Stockton CA Supercenter 38.0389 -121.242 1991
2300 WHITE LANE Bakersfield CA Wal-Mart 35.3442 -119.022 1991
355 ORO DAM BLVD Oroville CA Wal-Mart 39.5586 -121.589 1991
1977 WEST CLEVELAND AVE Madera CA Wal-Mart 36.9148 -120.158 1991
15272 BEAR VALLEY ROAD Victorville CA Wal-Mart 34.4895 -117.353 1991
911 SOUTH CHINA LAKE BLVD Ridgecrest CA Wal-Mart 35.5992 -117.681 1991
1025 SOUTH MAIN Red Bluff CA Wal-Mart 40.1838 -122.241 1991

... (149 rows omitted)

In [17]:
def color_from_type(type_store):
    if type_store == 'Wal-Mart':
        return 'blue'
    else:
        return 'red'
In [18]:
wm_ca = wm_ca.with_columns(
    'colors', wm_ca.apply(color_from_type, 'type_store')
)

wm_ca
Out[18]:
STREETADDR STRCITY STRSTATE type_store LAT LON YEAR colors
44765 VALLEY CENTRAL WAY Lancaster CA Wal-Mart 34.7289 -118.327 1990 blue
2150 NO. WATERMAN AVENUE El Centro CA Supercenter 32.7834 -115.577 1990 red
2225 PLAZA PARKWAY Modesto CA Wal-Mart 37.6718 -121.012 1990 blue
3223 EAST HAMMER LANE Stockton CA Supercenter 38.0389 -121.242 1991 red
2300 WHITE LANE Bakersfield CA Wal-Mart 35.3442 -119.022 1991 blue
355 ORO DAM BLVD Oroville CA Wal-Mart 39.5586 -121.589 1991 blue
1977 WEST CLEVELAND AVE Madera CA Wal-Mart 36.9148 -120.158 1991 blue
15272 BEAR VALLEY ROAD Victorville CA Wal-Mart 34.4895 -117.353 1991 blue
911 SOUTH CHINA LAKE BLVD Ridgecrest CA Wal-Mart 35.5992 -117.681 1991 blue
1025 SOUTH MAIN Red Bluff CA Wal-Mart 40.1838 -122.241 1991 blue

... (149 rows omitted)

In [19]:
wm_ca.select('LAT', 'LON', 'colors')
Out[19]:
LAT LON colors
34.7289 -118.327 blue
32.7834 -115.577 red
37.6718 -121.012 blue
38.0389 -121.242 red
35.3442 -119.022 blue
39.5586 -121.589 blue
36.9148 -120.158 blue
34.4895 -117.353 blue
35.5992 -117.681 blue
40.1838 -122.241 blue

... (149 rows omitted)

In [20]:
Circle.map_table(wm_ca.select('LAT', 'LON', 'colors'),
                fill_opacity = 0.6,
                line_color = None,
                area = 200)
Out[20]:
Make this Notebook Trusted to load map: File -> Trust Notebook

It seems like most Walmarts in California are standard locations and only a few are Supercenters.

What about in the rest of the country?

In [21]:
wm = wm.with_columns(
    'colors', wm.apply(color_from_type, 'type_store')
)

Circle.map_table(wm.select('LAT', 'LON', 'colors'),
                fill_opacity = 0.8,
                line_color = None,
                area = 20)
Out[21]:
Make this Notebook Trusted to load map: File -> Trust Notebook

In many large metro areas there is a concentration of standard Walmarts (blue). Supercenters are more common in the eastern part of the country.

Remember this data is from 2006; things have changed since then.

Quick Check 1

In [27]:
wm
Out[27]:
STREETADDR STRCITY STRSTATE type_store LAT LON YEAR colors
2110 WEST WALNUT Rogers AR Supercenter 36.3422 -94.0714 1962 red
1417 HWY 62/65 N Harrison AR Supercenter 36.237 -93.0935 1964 red
2901 HWY 412 EAST Siloam Springs AR Supercenter 36.1799 -94.5021 1965 red
1621 NORTH BUSINESS 9 Morrilton AR Supercenter 35.1565 -92.7586 1967 red
3801 CAMP ROBINSON RD. North Little Rock AR Wal-Mart 34.8133 -92.3023 1967 blue
2020 SOUTH MUSKOGEE Tahlequah OK Supercenter 35.9237 -94.9719 1968 red
2705 GRAND AVE Carthage MO Supercenter 37.169 -94.3116 1968 red
1500 LYNN RIGGS BLVD Claremore OK Supercenter 36.3271 -95.6119 1968 red
65 WAL-MART DRIVE Mountain Home AR Supercenter 36.329 -92.3578 1968 red
1303 SOUTH MAIN Sikeston MO Supercenter 36.8912 -89.5836 1968 red

... (2982 rows omitted)

In [29]:
# qc = wm.where('STRSTATE', 'AR') \
#        .select(..., ..., 'YEAR', ...) \
#        .relabeled('YEAR', ...)

# Circle.map_table(qc, 
#                  line_color = None, 
#                  fill_opacity = 0.7)

Maps with markers (pins)

In [35]:
wm_ca.select('LAT', 'LON', 'colors')
Out[35]:
LAT LON colors
34.7289 -118.327 blue
32.7834 -115.577 red
37.6718 -121.012 blue
38.0389 -121.242 red
35.3442 -119.022 blue
39.5586 -121.589 blue
36.9148 -120.158 blue
34.4895 -117.353 blue
35.5992 -117.681 blue
40.1838 -122.241 blue

... (149 rows omitted)

In [36]:
Marker.map_table(wm_ca.select('LAT', 'LON', 'colors'))
Out[36]:
Make this Notebook Trusted to load map: File -> Trust Notebook

marker_icon

Most icon names at this site work, but make sure to remove the term "glyphicon".

In [37]:
# Try changing 'shopping-cart' to 'off', 'euro', or 'remove'
Marker.map_table(wm_ca.select('LAT', 'LON', 'colors'), marker_icon = 'shopping-cart')
Out[37]:
Make this Notebook Trusted to load map: File -> Trust Notebook

clustered_marker

In [38]:
Marker.map_table(wm.select('LAT', 'LON'), clustered_marker = True, marker_icon = 'shopping-cart')
Out[38]:
Make this Notebook Trusted to load map: File -> Trust Notebook

Example: COVID cases

This data was pulled from Johns Hopkins' Center For Systems Science And Engineering on April 6th, 2021.

It describes the number of cumulative cases for each county, every day since January 22, 2020.

In [39]:
covid = Table.read_table('data/jhu-covid.csv')
In [40]:
covid
Out[40]:
UID iso2 iso3 code3 FIPS Admin2 Province_State Country_Region Lat Long_ Combined_Key 1/22/20 1/23/20 1/24/20 1/25/20 1/26/20 1/27/20 1/28/20 1/29/20 1/30/20 1/31/20 2/1/20 2/2/20 2/3/20 2/4/20 2/5/20 2/6/20 2/7/20 2/8/20 2/9/20 2/10/20 2/11/20 2/12/20 2/13/20 2/14/20 2/15/20 2/16/20 2/17/20 2/18/20 2/19/20 2/20/20 2/21/20 2/22/20 2/23/20 2/24/20 2/25/20 2/26/20 2/27/20 2/28/20 2/29/20 3/1/20 3/2/20 3/3/20 3/4/20 3/5/20 3/6/20 3/7/20 3/8/20 3/9/20 3/10/20 3/11/20 3/12/20 3/13/20 3/14/20 3/15/20 3/16/20 3/17/20 3/18/20 3/19/20 3/20/20 3/21/20 3/22/20 3/23/20 3/24/20 3/25/20 3/26/20 3/27/20 3/28/20 3/29/20 3/30/20 3/31/20 4/1/20 4/2/20 4/3/20 4/4/20 4/5/20 4/6/20 4/7/20 4/8/20 4/9/20 4/10/20 4/11/20 4/12/20 4/13/20 4/14/20 4/15/20 4/16/20 4/17/20 4/18/20 4/19/20 4/20/20 4/21/20 4/22/20 4/23/20 4/24/20 4/25/20 4/26/20 4/27/20 4/28/20 4/29/20 4/30/20 5/1/20 5/2/20 5/3/20 5/4/20 5/5/20 5/6/20 5/7/20 5/8/20 5/9/20 5/10/20 5/11/20 5/12/20 5/13/20 5/14/20 5/15/20 5/16/20 5/17/20 5/18/20 5/19/20 5/20/20 5/21/20 5/22/20 5/23/20 5/24/20 5/25/20 5/26/20 5/27/20 5/28/20 5/29/20 5/30/20 5/31/20 6/1/20 6/2/20 6/3/20 6/4/20 6/5/20 6/6/20 6/7/20 6/8/20 6/9/20 6/10/20 6/11/20 6/12/20 6/13/20 6/14/20 6/15/20 6/16/20 6/17/20 6/18/20 6/19/20 6/20/20 6/21/20 6/22/20 6/23/20 6/24/20 6/25/20 6/26/20 6/27/20 6/28/20 6/29/20 6/30/20 7/1/20 7/2/20 7/3/20 7/4/20 7/5/20 7/6/20 7/7/20 7/8/20 7/9/20 7/10/20 7/11/20 7/12/20 7/13/20 7/14/20 7/15/20 7/16/20 7/17/20 7/18/20 7/19/20 7/20/20 7/21/20 7/22/20 7/23/20 7/24/20 7/25/20 7/26/20 7/27/20 7/28/20 7/29/20 7/30/20 7/31/20 8/1/20 8/2/20 8/3/20 8/4/20 8/5/20 8/6/20 8/7/20 8/8/20 8/9/20 8/10/20 8/11/20 8/12/20 8/13/20 8/14/20 8/15/20 8/16/20 8/17/20 8/18/20 8/19/20 8/20/20 8/21/20 8/22/20 8/23/20 8/24/20 8/25/20 8/26/20 8/27/20 8/28/20 8/29/20 8/30/20 8/31/20 9/1/20 9/2/20 9/3/20 9/4/20 9/5/20 9/6/20 9/7/20 9/8/20 9/9/20 9/10/20 9/11/20 9/12/20 9/13/20 9/14/20 9/15/20 9/16/20 9/17/20 9/18/20 9/19/20 9/20/20 9/21/20 9/22/20 9/23/20 9/24/20 9/25/20 9/26/20 9/27/20 9/28/20 9/29/20 9/30/20 10/1/20 10/2/20 10/3/20 10/4/20 10/5/20 10/6/20 10/7/20 10/8/20 10/9/20 10/10/20 10/11/20 10/12/20 10/13/20 10/14/20 10/15/20 10/16/20 10/17/20 10/18/20 10/19/20 10/20/20 10/21/20 10/22/20 10/23/20 10/24/20 10/25/20 10/26/20 10/27/20 10/28/20 10/29/20 10/30/20 10/31/20 11/1/20 11/2/20 11/3/20 11/4/20 11/5/20 11/6/20 11/7/20 11/8/20 11/9/20 11/10/20 11/11/20 11/12/20 11/13/20 11/14/20 11/15/20 11/16/20 11/17/20 11/18/20 11/19/20 11/20/20 11/21/20 11/22/20 11/23/20 11/24/20 11/25/20 11/26/20 11/27/20 11/28/20 11/29/20 11/30/20 12/1/20 12/2/20 12/3/20 12/4/20 12/5/20 12/6/20 12/7/20 12/8/20 12/9/20 12/10/20 12/11/20 12/12/20 12/13/20 12/14/20 12/15/20 12/16/20 12/17/20 12/18/20 12/19/20 12/20/20 12/21/20 12/22/20 12/23/20 12/24/20 12/25/20 12/26/20 12/27/20 12/28/20 12/29/20 12/30/20 12/31/20 1/1/21 1/2/21 1/3/21 1/4/21 1/5/21 1/6/21 1/7/21 1/8/21 1/9/21 1/10/21 1/11/21 1/12/21 1/13/21 1/14/21 1/15/21 1/16/21 1/17/21 1/18/21 1/19/21 1/20/21 1/21/21 1/22/21 1/23/21 1/24/21 1/25/21 1/26/21 1/27/21 1/28/21 1/29/21 1/30/21 1/31/21 2/1/21 2/2/21 2/3/21 2/4/21 2/5/21 2/6/21 2/7/21 2/8/21 2/9/21 2/10/21 2/11/21 2/12/21 2/13/21 2/14/21 2/15/21 2/16/21 2/17/21 2/18/21 2/19/21 2/20/21 2/21/21 2/22/21 2/23/21 2/24/21 2/25/21 2/26/21 2/27/21 2/28/21 3/1/21 3/2/21 3/3/21 3/4/21 3/5/21 3/6/21 3/7/21 3/8/21 3/9/21 3/10/21 3/11/21 3/12/21 3/13/21 3/14/21 3/15/21 3/16/21 3/17/21 3/18/21 3/19/21 3/20/21 3/21/21 3/22/21 3/23/21 3/24/21 3/25/21 3/26/21 3/27/21 3/28/21 3/29/21 3/30/21 3/31/21 4/1/21 4/2/21 4/3/21 4/4/21 4/5/21
84001001 US USA 840 1001 Autauga Alabama US 32.5395 -86.6441 Autauga, Alabama, US 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 5 6 6 6 6 8 8 10 12 12 12 12 12 12 12 17 18 19 19 19 23 24 24 24 25 26 28 30 32 33 36 36 36 37 39 41 42 43 47 51 54 54 56 58 62 63 72 81 88 90 100 100 108 118 124 130 135 148 151 156 160 171 191 192 204 211 216 227 237 239 241 248 259 264 271 282 295 315 323 334 361 369 371 377 404 415 435 438 447 458 474 480 493 500 505 528 538 554 562 570 584 601 620 623 656 663 670 691 708 736 749 764 785 797 822 850 862 872 885 905 918 939 953 971 988 995 1006 1029 1042 1064 1078 1086 1086 1109 1126 1145 1175 1186 1200 1224 1229 1235 1245 1252 1258 1276 1281 1293 1304 1316 1318 1337 1343 1357 1365 1375 1391 1424 1429 1440 1442 1454 1462 1474 1477 1488 1494 1505 1526 1530 1543 1551 1567 1586 1601 1614 1650 1659 1675 1676 1697 1697 1711 1736 1750 1758 1770 1776 1785 1792 1799 1812 1821 1824 1832 1843 1847 1875 1894 1901 1907 1921 1925 1946 1958 1971 1985 1995 2006 2018 2021 2027 2040 2055 2070 2079 2098 2120 2134 2154 2168 2182 2195 2210 2229 2244 2257 2286 2307 2328 2328 2351 2385 2417 2435 2456 2481 2506 2529 2554 2580 2597 2617 2634 2661 2686 2704 2716 2735 2751 2780 2818 2873 2893 2945 2979 3005 3043 3087 3117 3186 3233 3258 3300 3329 3426 3510 3570 3647 3698 3741 3780 3841 3889 3942 3990 3999 4029 4065 4105 4164 4190 4239 4268 4305 4336 4546 4645 4705 4770 4847 4879 4902 4970 4998 5075 5103 5154 5184 5198 5227 5257 5270 5327 5358 5376 5407 5440 5499 5554 5596 5596 5669 5683 5723 5753 5811 5824 5856 5869 5881 5910 5930 5970 5984 6002 6023 6024 6038 6050 6071 6079 6092 6117 6121 6143 6172 6203 6228 6248 6264 6270 6303 6313 6324 6333 6344 6347 6364 6371 6400 6409 6409 6416 6426 6471 6474 6483 6495 6498 6510 6513 6517 6525 6533 6540 6543 6562 6570 6577 6580 6589 6595 6606 6617 6619 6620
84001003 US USA 840 1003 Baldwin Alabama US 30.7277 -87.7221 Baldwin, Alabama, US 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 2 2 2 3 5 5 6 6 18 19 22 23 26 29 31 34 39 43 47 54 63 64 70 75 82 93 100 104 106 110 116 120 126 134 143 148 155 161 167 172 174 180 180 185 190 190 194 199 207 211 219 224 226 230 237 247 253 261 267 267 269 277 277 278 280 281 284 285 289 289 290 292 298 299 301 302 305 312 321 327 332 338 350 357 365 367 375 377 379 389 402 408 418 426 439 453 466 505 549 573 628 668 691 739 831 847 861 893 979 1042 1118 1175 1215 1280 1349 1396 1506 1588 1675 1806 1925 1996 2085 2169 2344 2482 2610 2675 2733 2800 2873 3001 3075 3116 3194 3241 3298 3347 3409 3473 3533 3575 3676 3700 3749 3783 3825 3881 3923 3936 3959 3994 4029 4058 4100 4132 4148 4171 4247 4296 4330 4408 4502 4519 4538 4563 4599 4626 4654 4684 4700 4725 4755 4796 4845 4881 4915 4934 4949 4964 4982 4994 5016 5029 5053 5090 5106 5127 5397 5419 5465 5524 5550 5592 5954 5981 6009 6034 6045 6075 6103 6114 6144 6164 6176 6192 6222 6247 6266 6313 6332 6350 6356 6384 6425 6459 6599 6619 6642 6677 6694 6728 6757 6879 6931 6955 6974 6991 7054 7093 7133 7184 7226 7263 7345 7348 7409 7454 7523 7596 7646 7696 7772 7849 7933 8038 8131 8199 8269 8376 8473 8576 8603 8733 8820 8890 9051 9163 9341 9501 9626 9728 9821 9974 10087 10288 10489 10665 10806 10898 11061 11212 11364 11556 11722 11827 11952 12155 12321 12521 12666 12708 12825 12962 13172 13392 13601 13823 13955 14064 14187 14440 14656 14845 15052 15202 15327 15417 15572 15701 15841 16002 16176 16251 16346 16513 16653 16798 16981 17128 17256 17333 17496 17629 17779 17922 17922 18126 18211 18344 18418 18494 18568 18668 18723 18763 18824 18888 18960 18994 19051 19105 19136 19176 19267 19324 19361 19392 19433 19461 19554 19635 19670 19698 19714 19732 19758 19790 19856 19873 19890 19915 19935 19942 19962 20012 20044 20072 20091 20103 20210 20227 20263 20287 20317 20329 20347 20361 20354 20395 20417 20423 20453 20473 20487 20492 20505 20523 20519 20526 20541 20542
84001005 US USA 840 1005 Barbour Alabama US 31.8683 -85.3871 Barbour, Alabama, US 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 3 3 4 4 4 8 9 10 10 10 11 13 14 15 18 20 22 28 29 31 33 34 34 35 38 38 38 42 43 45 45 47 47 50 52 57 59 61 67 70 74 79 81 85 89 92 96 101 106 108 113 116 128 133 136 151 155 172 177 181 181 187 194 196 200 201 210 215 220 226 233 237 243 252 264 267 272 272 277 280 288 305 313 317 317 324 327 328 337 352 354 356 358 365 372 377 387 404 409 419 437 446 462 466 483 497 504 513 520 531 540 552 563 570 576 585 586 598 603 611 613 615 616 621 627 629 632 633 642 648 653 658 662 672 673 675 682 692 694 710 712 715 720 728 736 741 749 752 752 759 763 765 770 770 771 772 772 772 779 781 787 789 796 801 807 807 822 825 831 833 846 848 852 868 878 882 883 883 892 894 900 917 917 917 918 923 925 937 940 940 941 948 948 963 966 975 978 978 984 993 1007 1010 1028 1030 1030 1038 1042 1052 1053 1058 1059 1062 1073 1077 1079 1089 1092 1095 1098 1107 1107 1112 1113 1117 1123 1128 1130 1134 1137 1145 1151 1157 1160 1161 1167 1170 1170 1171 1173 1175 1178 1189 1206 1214 1217 1219 1223 1224 1240 1245 1258 1264 1269 1272 1275 1292 1296 1309 1318 1330 1336 1336 1363 1383 1390 1396 1398 1406 1417 1462 1492 1514 1517 1528 1530 1533 1575 1597 1614 1634 1648 1658 1663 1679 1685 1696 1712 1723 1729 1730 1738 1760 1778 1793 1805 1827 1834 1882 1898 1920 1931 1931 1951 1956 1966 1981 1989 1994 2002 2008 2008 2019 2024 2030 2036 2040 2042 2044 2055 2053 2057 2061 2067 2070 2074 2084 2095 2099 2106 2113 2115 2116 2124 2129 2136 2139 2138 2139 2143 2147 2161 2171 2175 2181 2184 2195 2198 2199 2202 2206 2212 2212 2213 2213 2216 2218 2221 2224 2226 2226 2227 2227 2227 2228 2231 2232 2232
84001007 US USA 840 1007 Bibb Alabama US 32.9964 -87.1251 Bibb, Alabama, US 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 2 3 3 3 4 4 4 7 7 8 9 11 11 13 16 17 18 19 23 23 26 26 30 30 32 32 33 34 37 40 40 40 40 41 41 42 43 43 43 44 44 45 46 46 46 46 47 51 52 52 53 53 54 54 56 59 60 63 68 72 72 72 74 77 78 78 78 78 79 79 81 87 91 95 97 102 106 113 113 116 119 125 125 126 128 134 141 148 161 164 164 167 172 176 181 191 193 196 198 202 204 214 219 226 229 232 237 243 248 255 262 270 277 283 288 290 304 318 324 335 339 345 353 364 369 373 383 390 393 420 424 434 446 450 454 465 469 475 479 481 485 487 501 507 512 515 521 521 522 526 530 532 539 550 553 558 562 564 567 571 576 578 585 586 589 593 594 596 599 600 601 606 607 619 623 624 628 633 637 646 649 650 651 653 660 668 671 675 683 683 688 700 703 715 724 734 736 741 742 759 769 773 783 787 789 799 809 823 825 839 841 849 858 862 867 873 877 883 890 900 907 920 926 934 942 948 948 961 966 973 978 986 993 1004 1008 1011 1024 1036 1136 1142 1157 1162 1170 1173 1179 1188 1196 1204 1239 1252 1270 1283 1293 1299 1317 1322 1359 1398 1417 1441 1455 1504 1520 1548 1577 1601 1613 1628 1660 1683 1711 1725 1739 1746 1762 1792 1817 1834 1854 1863 1882 1885 1923 1944 1981 2015 2038 2051 2060 2090 2109 2113 2130 2144 2151 2162 2170 2188 2198 2212 2223 2223 2229 2247 2261 2271 2284 2284 2307 2309 2319 2321 2327 2331 2334 2339 2346 2362 2368 2377 2385 2393 2395 2397 2400 2399 2405 2411 2414 2416 2417 2432 2437 2442 2445 2449 2450 2450 2454 2459 2461 2457 2460 2465 2464 2466 2469 2474 2475 2479 2481 2499 2508 2512 2519 2521 2528 2529 2529 2530 2535 2534 2535 2535 2536 2536 2537 2542 2543 2544 2545 2546 2546
84001009 US USA 840 1009 Blount Alabama US 33.9821 -86.5679 Blount, Alabama, US 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 4 6 6 7 7 7 7 9 11 12 13 13 13 13 15 15 15 17 18 19 21 22 22 24 25 27 31 33 35 36 36 38 38 38 39 39 41 42 42 42 42 44 46 47 47 47 48 48 48 48 48 49 49 50 50 50 51 52 52 52 52 54 56 61 63 65 66 66 66 66 67 73 76 78 80 84 92 98 106 114 120 121 125 135 140 144 151 155 162 170 177 186 192 192 200 209 218 221 232 236 240 249 257 270 289 301 316 338 354 368 390 426 445 464 487 510 526 549 582 616 639 654 674 679 701 738 773 799 820 838 841 845 883 917 929 945 957 971 979 994 998 1004 1014 1023 1060 1086 1113 1133 1147 1149 1160 1177 1224 1239 1251 1273 1301 1312 1332 1336 1356 1376 1392 1399 1416 1418 1424 1441 1453 1459 1472 1483 1490 1504 1515 1538 1551 1564 1573 1586 1593 1605 1614 1619 1623 1624 1626 1633 1636 1644 1656 1659 1664 1667 1678 1686 1700 1712 1720 1732 1755 1765 1782 1796 1822 1837 1848 1863 1887 1907 1923 1934 1947 1958 1986 2002 2027 2054 2089 2109 2128 2178 2204 2233 2258 2290 2302 2338 2378 2378 2400 2429 2488 2518 2549 2574 2594 2648 2683 2704 2735 2754 2763 2822 2855 2879 2888 2922 2946 2997 3061 3100 3158 3231 3281 3299 3324 3426 3496 3600 3663 3744 3776 3803 3881 3950 4036 4118 4191 4218 4234 4313 4367 4405 4441 4446 4465 4483 4535 4584 4641 4693 4729 4746 4771 4849 4898 4957 5018 5047 5066 5080 5134 5170 5219 5264 5292 5304 5308 5320 5376 5411 5439 5462 5473 5485 5517 5568 5612 5655 5655 5713 5720 5745 5768 5842 5871 5908 5915 5920 5929 5937 5955 5953 5957 5961 5973 5987 5997 6008 6021 6040 6042 6043 6058 6072 6086 6084 6095 6097 6102 6106 6229 6236 6246 6252 6256 6256 6255 6260 6274 6282 6288 6291 6353 6361 6371 6376 6380 6382 6383 6387 6388 6402 6408 6415 6420 6424 6426 6443 6444 6446 6455 6458 6459 6460
84001011 US USA 840 1011 Bullock Alabama US 32.1003 -85.7127 Bullock, Alabama, US 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 2 2 2 2 2 2 2 2 2 2 2 3 4 4 4 4 6 8 8 8 8 9 9 11 11 11 12 12 12 12 12 12 12 13 14 14 14 15 17 17 17 20 21 22 26 26 27 27 32 35 39 50 58 64 71 95 103 109 138 167 175 185 201 205 209 211 215 217 219 225 231 237 242 247 252 256 275 300 305 306 310 316 317 324 324 325 327 330 339 340 346 346 354 354 356 358 363 363 363 364 365 366 366 372 373 373 374 376 377 380 383 389 390 392 393 396 401 405 410 411 412 425 427 431 433 439 441 442 445 448 454 458 467 468 470 486 497 497 498 500 500 501 512 530 535 536 539 539 540 540 541 542 544 551 555 556 564 566 567 567 567 569 569 569 569 571 571 572 578 578 579 581 583 583 584 586 590 592 596 597 598 603 605 606 606 608 611 611 611 611 611 614 616 618 622 623 624 625 626 628 628 630 633 633 634 635 636 636 638 647 648 648 649 649 650 651 651 653 653 656 658 660 662 663 664 664 665 665 668 669 673 675 677 677 678 678 680 684 688 689 690 690 691 694 694 696 700 702 701 709 709 711 713 713 714 719 722 722 723 725 728 728 733 737 742 747 752 753 754 760 765 770 777 825 827 830 834 846 859 888 892 900 910 920 925 927 949 950 953 957 967 966 971 981 987 990 991 997 1011 1014 1022 1033 1035 1046 1058 1074 1079 1075 1075 1086 1089 1087 1093 1107 1113 1121 1128 1132 1132 1131 1136 1137 1139 1142 1142 1145 1143 1144 1147 1149 1151 1153 1160 1165 1163 1163 1167 1169 1169 1171 1172 1173 1174 1177 1177 1177 1177 1180 1181 1183 1185 1185 1193 1193 1193 1194 1194 1194 1194 1194 1195 1197 1200 1201 1202 1204 1204 1206 1207 1207 1207 1208 1209 1209
84001013 US USA 840 1013 Butler Alabama US 31.753 -86.6806 Butler, Alabama, US 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 3 3 6 7 8 8 11 11 13 14 15 15 15 17 19 21 28 32 34 48 53 55 68 93 104 113 118 128 152 159 175 188 196 223 231 244 254 265 278 289 297 306 315 325 329 338 360 375 387 389 394 403 413 414 418 420 430 441 447 453 462 469 482 498 517 534 542 545 548 560 562 563 567 569 572 574 580 586 593 595 598 599 599 602 614 615 624 624 625 630 632 639 645 646 650 651 655 659 662 668 676 678 685 693 699 705 712 718 724 728 734 740 746 749 756 758 758 761 763 766 766 771 774 775 778 780 786 796 799 803 803 805 809 811 813 815 816 817 824 827 829 845 855 857 865 867 868 872 875 879 881 881 882 883 884 886 888 889 890 892 893 896 897 897 898 898 899 901 903 906 907 908 911 913 915 917 919 920 921 923 926 928 937 948 954 958 964 974 979 985 987 993 996 996 996 999 1000 1005 1009 1011 1011 1014 1018 1018 1021 1023 1025 1028 1032 1035 1043 1045 1051 1053 1061 1061 1062 1062 1068 1075 1087 1095 1099 1102 1113 1120 1132 1133 1137 1143 1144 1153 1153 1165 1173 1178 1186 1188 1200 1211 1225 1236 1244 1257 1263 1287 1289 1306 1330 1340 1332 1343 1368 1384 1393 1399 1405 1412 1423 1434 1448 1446 1452 1457 1482 1493 1508 1522 1530 1546 1554 1574 1583 1598 1610 1625 1632 1637 1649 1651 1669 1679 1684 1696 1702 1707 1708 1713 1724 1731 1744 1748 1759 1766 1788 1800 1800 1812 1827 1833 1838 1847 1853 1863 1865 1868 1872 1882 1886 1892 1898 1902 1905 1910 1924 1930 1934 1938 1940 1945 1948 1951 1951 1952 1956 1961 1968 1975 2011 2014 2017 2014 2016 2017 2020 2022 2035 2037 2038 2041 2066 2068 2069 2069 2071 2072 2072 2072 2073 2077 2082 2087 2093 2096 2097 2098 2097 2103 2106 2106 2106 2107
84001015 US USA 840 1015 Calhoun Alabama US 33.7748 -85.8263 Calhoun, Alabama, US 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 2 2 2 2 4 4 4 9 10 11 12 22 23 26 40 51 54 56 56 59 63 64 65 66 68 68 71 78 82 85 87 89 89 90 91 91 94 95 97 97 102 109 109 118 120 126 129 130 130 131 132 133 134 135 136 139 139 142 142 143 145 145 148 153 157 159 159 160 161 169 172 172 174 176 181 183 184 186 188 190 193 197 201 202 203 206 208 208 209 211 213 214 223 233 236 245 245 261 276 278 288 330 341 363 375 390 412 443 460 496 520 562 580 649 663 706 728 772 813 849 870 893 974 1025 1086 1163 1206 1260 1305 1412 1445 1541 1570 1608 1645 1704 1744 1795 1821 1847 1874 1902 1925 1941 1980 2000 2015 2061 2121 2181 2211 2246 2260 2285 2302 2360 2380 2409 2468 2500 2530 2582 2606 2648 2714 2786 2797 2836 2840 2859 2900 2922 2975 3023 3040 3066 3106 3156 3189 3268 3289 3321 3341 3353 3412 3450 3466 3485 3498 3516 3530 3556 3597 3629 3647 3672 3700 3718 3736 3790 3811 3829 3848 3884 3911 3939 3992 4053 4071 4090 4115 4143 4175 4213 4553 4587 4602 4634 4675 4757 4800 4855 4883 4913 4946 4996 5030 5072 5146 5179 5214 5246 5254 5282 5345 5429 5470 5608 5666 5702 5764 5814 5896 5924 5964 5997 6049 6112 6215 6240 6301 6366 6430 6598 6695 6809 6939 7027 7096 7165 7300 7392 7534 7658 7760 7813 7872 7966 8072 8290 8459 8594 8648 8684 8856 8968 9071 9167 9198 9232 9286 9345 9428 9494 9584 9692 9731 9752 9975 10109 10283 10372 10453 10497 10537 10668 10745 10863 10982 11078 11122 11161 11206 11292 11365 11441 11496 11521 11555 11626 11730 11833 11918 11918 12011 12062 12102 12179 12253 12325 12368 12402 12426 12477 12498 12539 12577 12629 12700 12725 12756 12784 12833 12860 12915 12940 13017 13063 13090 13175 13202 13232 13275 13300 13307 13755 13832 13901 13961 13963 13968 13977 13989 14007 14034 14055 14064 14105 14112 14137 14148 14152 14158 14162 14165 14162 14186 14188 14192 14197 14199 14206 14216 14224 14227 14233 14243 14249 14251
84001017 US USA 840 1017 Chambers Alabama US 32.9136 -85.3907 Chambers, Alabama, US 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 2 2 6 9 13 15 22 29 39 40 51 75 87 91 94 102 112 145 170 178 189 206 215 219 229 234 239 242 247 257 259 266 273 277 279 281 284 286 288 292 295 296 302 307 309 313 317 320 323 325 327 332 333 334 335 337 337 338 339 342 343 343 343 349 350 353 356 364 367 369 370 373 374 375 379 389 393 398 407 418 434 443 457 474 486 488 491 503 507 515 520 527 533 540 547 558 560 560 581 590 594 609 620 631 634 643 652 658 672 678 690 694 703 713 719 732 743 756 762 767 774 781 789 796 810 820 824 835 844 848 859 862 869 876 882 887 894 900 905 906 909 915 918 919 922 925 927 928 937 943 949 965 969 970 970 973 982 1012 1015 1023 1024 1029 1037 1040 1041 1047 1053 1055 1058 1058 1061 1069 1079 1085 1085 1087 1092 1097 1097 1109 1114 1121 1123 1131 1135 1142 1151 1154 1157 1161 1164 1170 1172 1175 1195 1196 1199 1201 1203 1212 1231 1235 1235 1238 1247 1251 1255 1258 1261 1261 1268 1298 1328 1334 1341 1346 1347 1349 1365 1369 1379 1381 1389 1392 1397 1428 1449 1461 1469 1483 1485 1488 1506 1507 1508 1514 1545 1556 1570 1572 1595 1620 1641 1663 1669 1675 1680 1714 1737 1764 1765 1768 1772 1779 1827 1859 1875 1891 1901 1906 1915 1945 1961 1977 1982 1997 2013 2022 2040 2064 2076 2090 2116 2125 2133 2161 2176 2191 2200 2203 2214 2229 2275 2310 2341 2366 2386 2402 2415 2474 2519 2552 2592 2620 2639 2651 2697 2734 2757 2778 2818 2827 2842 2886 2931 2973 3011 3034 3042 3054 3085 3137 3159 3174 3174 3203 3210 3219 3233 3239 3249 3259 3263 3266 3283 3291 3305 3313 3318 3321 3325 3336 3338 3348 3358 3364 3367 3367 3382 3393 3392 3399 3406 3410 3413 3421 3423 3431 3432 3432 3434 3434 3435 3438 3438 3439 3441 3442 3457 3458 3460 3464 3465 3466 3466 3469 3470 3471 3478 3481 3484 3485 3485 3487 3488 3489 3489 3490 3493 3493
84001019 US USA 840 1019 Cherokee Alabama US 34.1781 -85.6064 Cherokee, Alabama, US 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 3 4 5 5 5 5 7 7 7 7 9 9 9 10 11 11 12 12 13 14 14 14 14 14 15 15 16 16 16 16 16 19 19 19 20 20 22 23 23 24 24 24 24 25 26 27 28 30 30 31 32 32 32 33 33 33 34 36 37 38 38 38 38 38 40 42 42 42 43 43 46 48 52 52 52 53 54 57 57 57 57 57 58 62 66 67 69 72 73 76 82 89 89 101 102 106 115 115 116 126 128 135 139 144 149 155 160 171 177 181 183 192 205 207 209 220 221 227 235 238 242 254 262 268 270 281 291 298 301 302 306 311 319 326 333 337 341 350 351 358 362 367 369 374 376 379 387 390 395 402 403 414 419 426 440 447 449 452 452 455 465 471 482 502 504 506 510 513 522 539 549 552 557 567 574 586 592 596 597 601 605 609 616 625 625 628 630 636 640 648 653 657 661 674 677 687 694 705 706 707 714 717 720 725 727 732 736 749 756 759 764 779 782 786 804 819 830 833 837 841 846 857 857 865 870 892 898 908 912 919 935 956 959 979 985 989 996 1008 1010 1015 1022 1029 1034 1051 1055 1067 1082 1090 1093 1110 1125 1134 1149 1167 1187 1197 1204 1213 1218 1241 1265 1278 1287 1294 1314 1329 1343 1368 1368 1369 1372 1393 1403 1414 1429 1435 1438 1441 1454 1468 1496 1517 1523 1537 1545 1568 1569 1583 1596 1600 1603 1605 1609 1619 1625 1643 1651 1657 1660 1674 1673 1682 1688 1688 1704 1707 1714 1718 1723 1724 1729 1730 1731 1735 1738 1738 1739 1742 1744 1745 1750 1750 1751 1751 1753 1753 1753 1757 1763 1764 1764 1768 1770 1770 1771 1777 1780 1781 1781 1782 1783 1784 1786 1785 1787 1788 1788 1791 1792 1791 1792 1793 1793 1794 1794 1794 1797 1798 1801 1804 1804 1804 1806 1806 1810 1811 1812 1812 1812

... (3332 rows omitted)

Let's aim to draw a map illustrating the average number of cases per day over the last 7 days in each county.

To do this, we take the number of cases on April 5, subtract from it the number of cases on March 29, and divide the result by 7.

In [41]:
april = covid.select('Combined_Key', 'Lat', 'Long_', '3/29/21', '4/5/21')
april
Out[41]:
Combined_Key Lat Long_ 3/29/21 4/5/21
Autauga, Alabama, US 32.5395 -86.6441 6577 6620
Baldwin, Alabama, US 30.7277 -87.7221 20487 20542
Barbour, Alabama, US 31.8683 -85.3871 2226 2232
Bibb, Alabama, US 32.9964 -87.1251 2536 2546
Blount, Alabama, US 33.9821 -86.5679 6426 6460
Bullock, Alabama, US 32.1003 -85.7127 1204 1209
Butler, Alabama, US 31.753 -86.6806 2097 2107
Calhoun, Alabama, US 33.7748 -85.8263 14206 14251
Chambers, Alabama, US 32.9136 -85.3907 3485 3493
Cherokee, Alabama, US 34.1781 -85.6064 1804 1812

... (3332 rows omitted)

In [42]:
april = april.with_columns(
    '7-day avg', np.round((april.column('4/5/21') - april.column('3/29/21')) / 7)
)

april
Out[42]:
Combined_Key Lat Long_ 3/29/21 4/5/21 7-day avg
Autauga, Alabama, US 32.5395 -86.6441 6577 6620 6
Baldwin, Alabama, US 30.7277 -87.7221 20487 20542 8
Barbour, Alabama, US 31.8683 -85.3871 2226 2232 1
Bibb, Alabama, US 32.9964 -87.1251 2536 2546 1
Blount, Alabama, US 33.9821 -86.5679 6426 6460 5
Bullock, Alabama, US 32.1003 -85.7127 1204 1209 1
Butler, Alabama, US 31.753 -86.6806 2097 2107 1
Calhoun, Alabama, US 33.7748 -85.8263 14206 14251 6
Chambers, Alabama, US 32.9136 -85.3907 3485 3493 1
Cherokee, Alabama, US 34.1781 -85.6064 1804 1812 1

... (3332 rows omitted)

We need to relabel our columns in order to prepare our table for Circle.map_table.

In [43]:
april_for_map = april.select('Lat', 'Long_', 'Combined_Key', '7-day avg') \
     .relabeled(['Combined_Key', '7-day avg'], ['labels', 'color_scale'])

april_for_map
Out[43]:
Lat Long_ labels color_scale
32.5395 -86.6441 Autauga, Alabama, US 6
30.7277 -87.7221 Baldwin, Alabama, US 8
31.8683 -85.3871 Barbour, Alabama, US 1
32.9964 -87.1251 Bibb, Alabama, US 1
33.9821 -86.5679 Blount, Alabama, US 5
32.1003 -85.7127 Bullock, Alabama, US 1
31.753 -86.6806 Butler, Alabama, US 1
33.7748 -85.8263 Calhoun, Alabama, US 6
32.9136 -85.3907 Chambers, Alabama, US 1
34.1781 -85.6064 Cherokee, Alabama, US 1

... (3332 rows omitted)

There's something weird – there are a few counties whose 7-day average is negative. This is almost certainly due to some data logging issues; we will need to drop these rows before continuing as they'll mess up our color scale.

In [44]:
april_for_map.sort('color_scale')
Out[44]:
Lat Long_ labels color_scale
0 0 Out of GA, Georgia, US -68
0 0 Unassigned, Oklahoma, US -34
0 0 Unassigned, Arkansas, US -21
0 0 Unassigned, Georgia, US -15
37.0208 -88.0789 Lyon, Kentucky, US -13
0 0 Unassigned, New Jersey, US -10
0 0 Out of TN, Tennessee, US -10
31.2535 -96.9363 Falls, Texas, US -6
31.8153 -95.6535 Anderson, Texas, US -4
30.1188 -93.8941 Orange, Texas, US -4

... (3332 rows omitted)

In [45]:
april_for_map = april_for_map.where('color_scale', are.above_or_equal_to(0))

Time to call Circle.map_table.

In [46]:
Circle.map_table(april_for_map,
                area = 50,
                fill_opacity = 1,
                line_color = None)
Out[46]:
Make this Notebook Trusted to load map: File -> Trust Notebook

We can take things a step further by creating more informative labels.

In [47]:
april
Out[47]:
Combined_Key Lat Long_ 3/29/21 4/5/21 7-day avg
Autauga, Alabama, US 32.5395 -86.6441 6577 6620 6
Baldwin, Alabama, US 30.7277 -87.7221 20487 20542 8
Barbour, Alabama, US 31.8683 -85.3871 2226 2232 1
Bibb, Alabama, US 32.9964 -87.1251 2536 2546 1
Blount, Alabama, US 33.9821 -86.5679 6426 6460 5
Bullock, Alabama, US 32.1003 -85.7127 1204 1209 1
Butler, Alabama, US 31.753 -86.6806 2097 2107 1
Calhoun, Alabama, US 33.7748 -85.8263 14206 14251 6
Chambers, Alabama, US 32.9136 -85.3907 3485 3493 1
Cherokee, Alabama, US 34.1781 -85.6064 1804 1812 1

... (3332 rows omitted)

In [48]:
def make_label(name, avg):
    name_no_us = name.replace(', US', '')
    s = '<b>' + name_no_us + '</b>' + '<br>'
    s += '7-day avg: ' + str(int(avg))
    return s
In [49]:
print(make_label('Autauga, Alabama, US', 6))
<b>Autauga, Alabama</b><br>7-day avg: 6
In [50]:
april.apply(make_label, 'Combined_Key', '7-day avg')
Out[50]:
array(['<b>Autauga, Alabama</b><br>7-day avg: 6',
       '<b>Baldwin, Alabama</b><br>7-day avg: 8',
       '<b>Barbour, Alabama</b><br>7-day avg: 1', ...,
       '<b>Unassigned, Wyoming</b><br>7-day avg: 0',
       '<b>Washakie, Wyoming</b><br>7-day avg: 0',
       '<b>Weston, Wyoming</b><br>7-day avg: 0'], dtype='<U75')
In [51]:
april_for_new_map = april.with_columns(
    'labels', april.apply(make_label, 'Combined_Key', '7-day avg')
).select('Lat', 'Long_', 'labels', '7-day avg') \
 .relabeled('7-day avg', 'color_scale') \
 .where('color_scale', are.above_or_equal_to(0))

april_for_new_map
Out[51]:
Lat Long_ labels color_scale
32.5395 -86.6441 Autauga, Alabama
7-day avg: 6
6
30.7277 -87.7221 Baldwin, Alabama
7-day avg: 8
8
31.8683 -85.3871 Barbour, Alabama
7-day avg: 1
1
32.9964 -87.1251 Bibb, Alabama
7-day avg: 1
1
33.9821 -86.5679 Blount, Alabama
7-day avg: 5
5
32.1003 -85.7127 Bullock, Alabama
7-day avg: 1
1
31.753 -86.6806 Butler, Alabama
7-day avg: 1
1
33.7748 -85.8263 Calhoun, Alabama
7-day avg: 6
6
32.9136 -85.3907 Chambers, Alabama
7-day avg: 1
1
34.1781 -85.6064 Cherokee, Alabama
7-day avg: 1
1

... (3304 rows omitted)

In [52]:
Circle.map_table(april_for_new_map,
                area = 50,
                fill_opacity = 1,
                line_color = None)
Out[52]:
Make this Notebook Trusted to load map: File -> Trust Notebook

Now each circle tells you the county name and the average number of COVID cases over the past 7 days in that county.

Extra: cumulative cases in Alameda county

Note: The exploration here won't be covered in lecture, and includes programming that is slightly more involved than you'll be responsible for. Nevertheless, you may find it interesting, so take a look!

The dataset has columns for each date; we want rows, because that's what plot expects.

In [53]:
alameda = covid.where('Admin2', 'Alameda').select(np.arange(11, covid.num_columns))
alameda
Out[53]:
1/22/20 1/23/20 1/24/20 1/25/20 1/26/20 1/27/20 1/28/20 1/29/20 1/30/20 1/31/20 2/1/20 2/2/20 2/3/20 2/4/20 2/5/20 2/6/20 2/7/20 2/8/20 2/9/20 2/10/20 2/11/20 2/12/20 2/13/20 2/14/20 2/15/20 2/16/20 2/17/20 2/18/20 2/19/20 2/20/20 2/21/20 2/22/20 2/23/20 2/24/20 2/25/20 2/26/20 2/27/20 2/28/20 2/29/20 3/1/20 3/2/20 3/3/20 3/4/20 3/5/20 3/6/20 3/7/20 3/8/20 3/9/20 3/10/20 3/11/20 3/12/20 3/13/20 3/14/20 3/15/20 3/16/20 3/17/20 3/18/20 3/19/20 3/20/20 3/21/20 3/22/20 3/23/20 3/24/20 3/25/20 3/26/20 3/27/20 3/28/20 3/29/20 3/30/20 3/31/20 4/1/20 4/2/20 4/3/20 4/4/20 4/5/20 4/6/20 4/7/20 4/8/20 4/9/20 4/10/20 4/11/20 4/12/20 4/13/20 4/14/20 4/15/20 4/16/20 4/17/20 4/18/20 4/19/20 4/20/20 4/21/20 4/22/20 4/23/20 4/24/20 4/25/20 4/26/20 4/27/20 4/28/20 4/29/20 4/30/20 5/1/20 5/2/20 5/3/20 5/4/20 5/5/20 5/6/20 5/7/20 5/8/20 5/9/20 5/10/20 5/11/20 5/12/20 5/13/20 5/14/20 5/15/20 5/16/20 5/17/20 5/18/20 5/19/20 5/20/20 5/21/20 5/22/20 5/23/20 5/24/20 5/25/20 5/26/20 5/27/20 5/28/20 5/29/20 5/30/20 5/31/20 6/1/20 6/2/20 6/3/20 6/4/20 6/5/20 6/6/20 6/7/20 6/8/20 6/9/20 6/10/20 6/11/20 6/12/20 6/13/20 6/14/20 6/15/20 6/16/20 6/17/20 6/18/20 6/19/20 6/20/20 6/21/20 6/22/20 6/23/20 6/24/20 6/25/20 6/26/20 6/27/20 6/28/20 6/29/20 6/30/20 7/1/20 7/2/20 7/3/20 7/4/20 7/5/20 7/6/20 7/7/20 7/8/20 7/9/20 7/10/20 7/11/20 7/12/20 7/13/20 7/14/20 7/15/20 7/16/20 7/17/20 7/18/20 7/19/20 7/20/20 7/21/20 7/22/20 7/23/20 7/24/20 7/25/20 7/26/20 7/27/20 7/28/20 7/29/20 7/30/20 7/31/20 8/1/20 8/2/20 8/3/20 8/4/20 8/5/20 8/6/20 8/7/20 8/8/20 8/9/20 8/10/20 8/11/20 8/12/20 8/13/20 8/14/20 8/15/20 8/16/20 8/17/20 8/18/20 8/19/20 8/20/20 8/21/20 8/22/20 8/23/20 8/24/20 8/25/20 8/26/20 8/27/20 8/28/20 8/29/20 8/30/20 8/31/20 9/1/20 9/2/20 9/3/20 9/4/20 9/5/20 9/6/20 9/7/20 9/8/20 9/9/20 9/10/20 9/11/20 9/12/20 9/13/20 9/14/20 9/15/20 9/16/20 9/17/20 9/18/20 9/19/20 9/20/20 9/21/20 9/22/20 9/23/20 9/24/20 9/25/20 9/26/20 9/27/20 9/28/20 9/29/20 9/30/20 10/1/20 10/2/20 10/3/20 10/4/20 10/5/20 10/6/20 10/7/20 10/8/20 10/9/20 10/10/20 10/11/20 10/12/20 10/13/20 10/14/20 10/15/20 10/16/20 10/17/20 10/18/20 10/19/20 10/20/20 10/21/20 10/22/20 10/23/20 10/24/20 10/25/20 10/26/20 10/27/20 10/28/20 10/29/20 10/30/20 10/31/20 11/1/20 11/2/20 11/3/20 11/4/20 11/5/20 11/6/20 11/7/20 11/8/20 11/9/20 11/10/20 11/11/20 11/12/20 11/13/20 11/14/20 11/15/20 11/16/20 11/17/20 11/18/20 11/19/20 11/20/20 11/21/20 11/22/20 11/23/20 11/24/20 11/25/20 11/26/20 11/27/20 11/28/20 11/29/20 11/30/20 12/1/20 12/2/20 12/3/20 12/4/20 12/5/20 12/6/20 12/7/20 12/8/20 12/9/20 12/10/20 12/11/20 12/12/20 12/13/20 12/14/20 12/15/20 12/16/20 12/17/20 12/18/20 12/19/20 12/20/20 12/21/20 12/22/20 12/23/20 12/24/20 12/25/20 12/26/20 12/27/20 12/28/20 12/29/20 12/30/20 12/31/20 1/1/21 1/2/21 1/3/21 1/4/21 1/5/21 1/6/21 1/7/21 1/8/21 1/9/21 1/10/21 1/11/21 1/12/21 1/13/21 1/14/21 1/15/21 1/16/21 1/17/21 1/18/21 1/19/21 1/20/21 1/21/21 1/22/21 1/23/21 1/24/21 1/25/21 1/26/21 1/27/21 1/28/21 1/29/21 1/30/21 1/31/21 2/1/21 2/2/21 2/3/21 2/4/21 2/5/21 2/6/21 2/7/21 2/8/21 2/9/21 2/10/21 2/11/21 2/12/21 2/13/21 2/14/21 2/15/21 2/16/21 2/17/21 2/18/21 2/19/21 2/20/21 2/21/21 2/22/21 2/23/21 2/24/21 2/25/21 2/26/21 2/27/21 2/28/21 3/1/21 3/2/21 3/3/21 3/4/21 3/5/21 3/6/21 3/7/21 3/8/21 3/9/21 3/10/21 3/11/21 3/12/21 3/13/21 3/14/21 3/15/21 3/16/21 3/17/21 3/18/21 3/19/21 3/20/21 3/21/21 3/22/21 3/23/21 3/24/21 3/25/21 3/26/21 3/27/21 3/28/21 3/29/21 3/30/21 3/31/21 4/1/21 4/2/21 4/3/21 4/4/21 4/5/21
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 2 2 2 3 5 5 7 11 11 18 27 30 38 48 68 71 118 135 135 178 220 220 270 283 313 313 359 443 443 566 588 634 674 674 766 806 845 888 888 964 1007 1063 1114 1164 1193 1241 1242 1352 1403 1439 1470 1500 1533 1568 1603 1636 1706 1749 1776 1809 1863 1917 1961 2023 2064 2101 2133 2178 2234 2367 2351 2392 2457 2522 2560 2609 2708 2760 2847 2874 2986 3049 3097 3195 3289 3390 3470 3515 3548 3641 3725 3805 3805 3945 3985 4033 4232 4216 4217 4320 4373 4481 4533 4638 4702 4924 4924 5007 5267 5275 5382 5493 5493 5670 5762 5964 6156 6384 6472 6556 6855 6855 6925 7245 7407 7485 7725 7731 7976 8321 8478 8627 8858 9110 9237 9256 9383 9643 9869 10214 10330 10330 10438 10633 10773 11131 11139 11484 11524 11524 11909 12136 12884 12884 13213 13213 13631 13631 14112 14548 14558 14558 14973 15123 15437 15836 16184 16469 16693 16723 16786 17275 17385 17621 17847 17847 18040 18187 18445 18695 18852 18977 19131 19131 19350 19496 19596 19710 19819 19837 19991 20022 20097 20097 20162 20364 20494 20558 20641 20748 20839 20951 21028 21136 21189 21240 21323 21383 21458 21508 21621 21708 21746 21809 21845 21938 21942 22072 22149 22216 22279 22325 22370 22408 22459 22636 22738 22807 22932 23001 23133 23215 23312 23391 23471 23576 23636 23775 23876 23994 24095 24162 24233 24370 24418 24664 24851 25001 25110 25249 25400 25599 25760 25872 26047 26460 26655 26927 27223 27435 27485 27622 27857 28225 28378 28857 29116 29476 29918 29972 30330 30980 31204 31871 32781 33477 33887 34373 35047 35686 36281 37027 38218 39252 40026 40751 41548 42196 43109 44004 44756 45751 46753 47527 48365 49084 49796 50405 50946 51590 52475 53518 54518 55073 55899 56432 57081 57921 59172 60125 61111 62046 62943 63866 64760 65679 68016 67375 67952 68649 69107 69554 69693 70334 70823 71298 72024 72597 73115 73542 73771 74087 74661 74959 75175 78224 75737 76170 76648 77109 77216 77632 77926 78285 78356 78714 78883 79016 79092 79297 79471 79539 79649 79796 79948 80088 80279 80496 80668 80777 80873 80950 81086 81168 81255 81345 81433 81573 81658 81747 81866 81969 82034 82116 82168 82258 82368 82460 82540 82593 82680 82747 82818 82871 82945 83043 83169 83243 83338 83395 83475 83574 83776 83861 83951

That's not a problem:

In [54]:
alameda_rotated = Table().with_columns(
    'Date', alameda.labels,
    'Cases', alameda.row(0)
)

alameda_rotated
Out[54]:
Date Cases
1/22/20 0
1/23/20 0
1/24/20 0
1/25/20 0
1/26/20 0
1/27/20 0
1/28/20 0
1/29/20 0
1/30/20 0
1/31/20 0

... (430 rows omitted)

What is a problem is that the date is not in a format that datascience recognizes as being a number. There's a solution; run the following cell to implement it.

In [56]:
from datetime import datetime

def convert_date(date):
    return datetime.strptime(date, '%m/%d/%y')

alameda_rotated = alameda_rotated.with_columns(
    'Date', alameda_rotated.apply(convert_date, 'Date')
)

alameda_rotated
Out[56]:
Date Cases
2020-01-22 00:00:00 0
2020-01-23 00:00:00 0
2020-01-24 00:00:00 0
2020-01-25 00:00:00 0
2020-01-26 00:00:00 0
2020-01-27 00:00:00 0
2020-01-28 00:00:00 0
2020-01-29 00:00:00 0
2020-01-30 00:00:00 0
2020-01-31 00:00:00 0

... (430 rows omitted)

Great, now run the following cell to draw the line plot:

In [57]:
alameda_rotated.plot('Date',
                    title = 'Total Number of COVID-19 Cases in Alameda County')

Awesome. But what if we want the number of new cases per day? We can compute that too, using np.diff. np.diff subtracts consecutive elements in an array. (Notice that when we call np.diff on an array of length n, the result is an array of length n-1.)

In [58]:
np.diff(np.array([5, 4, 9, 1, 8]))
Out[58]:
array([-1,  5, -8,  7])

We can use it on the 'Cases' column of alameda_rotated.

In [59]:
alameda_rotated = alameda_rotated.with_columns(
    'New Cases', np.append(0, np.diff(alameda_rotated.column('Cases')))
)

alameda_rotated
Out[59]:
Date Cases New Cases
2020-01-22 00:00:00 0 0
2020-01-23 00:00:00 0 0
2020-01-24 00:00:00 0 0
2020-01-25 00:00:00 0 0
2020-01-26 00:00:00 0 0
2020-01-27 00:00:00 0 0
2020-01-28 00:00:00 0 0
2020-01-29 00:00:00 0 0
2020-01-30 00:00:00 0 0
2020-01-31 00:00:00 0 0

... (430 rows omitted)

In [60]:
alameda_rotated.plot('Date', 'New Cases',
                    title = 'Number of New COVID-19 Cases in Alameda County Per Day')

Hmm – there are a few jumps that don't quite seem right. What do you think happened? 🤔

(Hint: hover over the values for February 5, February 6, and February 7. What happens when you add the values for February 5 and February 6?)