from datascience import *
import numpy as np
Table.interactive_plots()
wm = Table.read_table('data/walmart.csv').select('STREETADDR', 'STRCITY', 'STRSTATE', 'type_store', 'LAT', 'LON', 'YEAR')
wm
wm.group('YEAR')
wm.group('YEAR').plot('YEAR',
title = 'Number of Walmarts Opened Per Year')
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
wm_per_year.plot('YEAR', 'total',
title = 'Total Number of Walmarts Over Time')
wm_ca = wm.where('STRSTATE', 'CA')
wm_ca
wm_ca.select('LAT', 'LON')
Circle.map_table(wm_ca.select('LAT', 'LON'))
Circle.map_table(wm_ca.select('LAT', 'LON'),
area = 200,
weight = 1.5,
line_color = 'gold',
color = 'purple',
fill_opacity = 0.8
)
labels¶wm_ca.select('LAT', 'LON', 'STREETADDR')
wm_ca_labeled = wm_ca.select('LAT', 'LON', 'STREETADDR').relabeled('STREETADDR', 'labels')
wm_ca_labeled
Circle.map_table(wm_ca_labeled)
color_scale¶wm_ca_scales = wm_ca.select('LAT', 'LON', 'STRCITY', 'YEAR') \
.relabeled(['STRCITY', 'YEAR'], ['labels', 'color_scale'])
wm_ca_scales
Circle.map_table(wm_ca_scales,
fill_opacity = 0.8,
line_color = None,
area = 200)
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¶wm_ca
def color_from_type(type_store):
if type_store == 'Wal-Mart':
return 'blue'
else:
return 'red'
wm_ca = wm_ca.with_columns(
'colors', wm_ca.apply(color_from_type, 'type_store')
)
wm_ca
wm_ca.select('LAT', 'LON', 'colors')
Circle.map_table(wm_ca.select('LAT', 'LON', 'colors'),
fill_opacity = 0.6,
line_color = None,
area = 200)
It seems like most Walmarts in California are standard locations and only a few are Supercenters.
What about in the rest of the country?
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)