cannabis_licenses / analysis /license_map.py
keeganskeate's picture
pr/2 (#2)
124701c
raw
history blame
2.47 kB
"""
Cannabis Licenses | License Mao
Copyright (c) 2022 Cannlytics
Authors:
Keegan Skeate <https://github.com/keeganskeate>
Candace O'Sullivan-Sutherland <https://github.com/candy-o>
Created: 9/22/2022
Updated: 9/30/2022
License: <https://github.com/cannlytics/cannabis-data-science/blob/main/LICENSE>
Description:
Map the adult-use cannabis retailers permitted in the United States:
- Alaska
- Arizona
βœ“ California
- Colorado
- Connecticut
- Illinois
βœ“ Maine
- Massachusetts
- Michigan
- Montana
βœ“ Nevada
βœ“ New Jersey
- New Mexico
- New York
βœ“ Oregon
- Rhode Island
- Vermont
βœ“ Washington
"""
# Standard imports.
import os
# External imports.
import folium
import pandas as pd
# Specify where your data lives.
DATA_DIR = '../data'
DATA_FILES = {
'ca': 'ca/licenses-ca-2022-09-21T19-02-29.xlsx',
'me': 'me/licenses-me-2022-09-30T16-44-03.xlsx',
'nj': 'nj/licenses-nj-2022-09-29T16-17-38.xlsx',
'nv': 'nv/retailers-nv-2022-09-30T07-41-59.xlsx',
'or': 'or/licenses-or-2022-09-28T10-11-12.xlsx',
'wa': 'wa/licenses-wa-2022-09-29T14-44-25.xlsx',
}
#-----------------------------------------------------------------------
# Get the data.
#-----------------------------------------------------------------------
# Read license data for each state.
data = []
for state, data_file in DATA_FILES.items():
filename = os.path.join(DATA_DIR, DATA_FILES[state])
licenses = pd.read_excel(filename, index_col=0)
data.append(licenses)
# Aggregate all retailers and keep only those with latitude and longitude.
retailers = pd.concat(data)
retailers = retailers.loc[
(~retailers['premise_longitude'].isnull()) &
(~retailers['premise_latitude'].isnull())
]
#-----------------------------------------------------------------------
# Look at the data!
#-----------------------------------------------------------------------
# Create an interactive map.
locations = retailers[['premise_latitude', 'premise_longitude']].to_numpy()
m = folium.Map(
location=[39.8283, -98.5795],
zoom_start=3,
control_scale=True,
)
for index, row in retailers.iterrows():
folium.Circle(
radius=5,
location=[row['premise_latitude'], row['premise_longitude']],
color='crimson',
).add_to(m)
m.save('../analysis/figures/cannabis-licenses-map.html')