In [2]:
import csv

with open('just tacos and burritos.csv') as csvfile:
    reader = csv.DictReader(csvfile)
    test_data = []
    for row in reader:
         test_data.append(row)
    print(len(test_data))
77260
test_data[0]
In [51]:
from collections import defaultdict, Counter
toppings_by_state = defaultdict(dict)
toppings_by_state = defaultdict(Counter)

meats = ['beef', 'chicken', 'pork', 'steak', 'fajita', 'tripe', 'asada', 'lingua', 'sesos', 'cabaza', 'fish']
types_of_fish = ['ahui', 'tuna', 'salmon']
for menu_item in test_data:
    if 'taco' in (menu_item['menus.name'] + menu_item['menus.description']).lower(): # join item name and description
        if len(menu_item['province']) == 2:
            state = menu_item['province']
            #for description_item in menu_item['menus.description'].split(' '):
            #    if description_item not in [' ', 'and', '', 'with', 'a', 'red', 'or', 'shredded', 'ground', 'flour', 'of', 'taco', 'on', 'soft',
            #                               'filled', 'tacos', 'tortillas', 'sour', 'crisp', 'de']: #ignore uninteresting toppings
            #        state_toppings = toppings_by_state[state].get(description_item, 0)
            #        state_toppings += 1
            #        toppings_by_state[state][description_item] = state_toppings
            for meat in meats:
                added_as_fish = False
                if meat in (menu_item['menus.name'] + menu_item['menus.description']).lower():
                    #state_toppings = toppings_by_state[state].get(meat, 0)
                    #state_toppings += 1
                    #toppings_by_state[state][meat] = state_toppings
                    toppings_by_state[state][meat] += 1
                    if meat == 'fish':
                        added_as_fish = True
                    break
                if not added_as_fish:
                    for fish_type in types_of_fish:
                        if fish_type in (menu_item['menus.name'] + menu_item['menus.description']).lower():
                            #state_toppings = toppings_by_state[state].get('fish', 0)
                            #state_toppings += 1
                            #toppings_by_state[state]['fish'] = state_toppings
                            toppings_by_state[state]['fish'] += 1
                            break
                            
                    
In [52]:
for state in toppings_by_state:
    max_state_topping_count = 0
    for topping in toppings_by_state[state]:
        if toppings_by_state[state][topping] > max_state_topping_count:
            max_state_topping_count = toppings_by_state[state][topping]
            max_state_topping = topping
    print state, max_state_topping, max_state_topping_count
WA fish 161
DE fish 34
DC fish 115
WI beef 53
WV fish 17
HI fish 22
FL fish 615
WY beef 17
NH beef 31
NJ fish 217
NM fish 78
TX beef 962
LA beef 57
AK beef 8
NC fish 114
ND chicken 4
NE fish 50
TN fish 117
NY fish 367
PA fish 182
RI fish 22
NV fish 224
VA fish 148
CO fish 216
VI fish 2
CA fish 3706
AL beef 66
AR beef 27
VT fish 3
IL fish 214
GA fish 171
IN fish 95
IA beef 43
OK fish 119
AZ fish 318
ID beef 42
CT fish 126
ME fish 15
MD fish 169
MA fish 304
OH fish 127
UT beef 72
MO fish 104
MN fish 98
MI fish 149
KS beef 47
MT fish 30
MS chicken 26
SC fish 85
KY chicken 31
OR beef 125
SD chicken 8
In [61]:
beef_states = {}
fish_states  = {}
chicken_states = {}
for state in toppings_by_state:
    if len(toppings_by_state[state].most_common(3)) == 3:
        first, second, third = toppings_by_state[state].most_common(3)
        ratio = first[1] / (first[1] + second[1] + third[1])
        if first[0] == 'chicken':
            chicken_states[state] = ratio
        if first[0] == 'fish':
            fish_states[state] = ratio
        if first[0] == 'beef':
            beef_states[state] = ratio

    
    
        
In [70]:
import pandas as pd
import folium

url = 'https://raw.githubusercontent.com/python-visualization/folium/master/examples/data'
state_geo = '{url}/us-states.json'.format(url=url)

m = folium.Map(location=[48, -102], zoom_start=3)

folium.Choropleth(
    geo_data=state_geo,
    name='choropleth',
    data=beef_states,
    columns=['State', 'Beef Taco Ratio'],
    key_on='feature.id',
    fill_color='YlGn',
    fill_opacity=.4,
    line_opacity=0.2,
    legend_name='Beef Taco Rate (%)'
).add_to(m)

folium.Choropleth(
    geo_data=state_geo,
    name='choropleth',
    data=fish_states,
    columns=['State', 'Fish Taco Ratio'],
    key_on='feature.id',
    fill_color='PuBu',
    fill_opacity=.4,
    line_opacity=0.2,
    legend_name='Fish Taco Rate (%)'
).add_to(m)

folium.Choropleth(
    geo_data=state_geo,
    name='choropleth',
    data=chicken_states,
    columns=['State', 'Chicken Taco Ratio'],
    key_on='feature.id',
    fill_color='Oranges',
    fill_opacity=.4,
    line_opacity=0.2,
    legend_name='Chicken Taco Rate (%)'
).add_to(m)

folium.LayerControl().add_to(m)

m
Out[70]: