In [56]:
%matplotlib inline
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
import pandas as pd
import glob
import os
import scipy as sp
from scipy import sparse
from scipy import stats
from matplotlib import cm
import itertools
from mpl_toolkits.basemap import Basemap, cm
from scipy.stats import spearmanr
import statsmodels.api as sm
from statsmodels.formula.api import ols
In [2]:
df_cities = pd.read_csv('city_pop.csv', index_col=0)
df_cities
Out[2]:
city
state
population
total_food
latitude
longitude
total_scraped
0
New York
New York
8537673
54191
40.705445
-73.994293
1000
1
Los Angeles
California
3976322
41685
34.061590
-118.321381
1000
2
Chicago
Illinois
2704958
19315
41.905159
-87.677765
1000
3
Houston
Texas
2303482
15197
29.784854
-95.359955
1000
4
Phoenix
Arizona
1615017
11034
33.465086
-112.070160
1000
5
Philadelphia
Pennsylvania
1567872
15438
39.953782
-75.171204
1000
6
San Antonio
Texas
1492510
6273
29.494438
-98.514404
1000
7
San Diego
California
1406630
13666
32.790569
-117.154083
1000
8
Dallas
Texas
1317929
14633
32.839043
-96.800537
1000
9
San Jose
California
1025350
10755
37.316481
-121.885071
1000
10
Austin
Texas
947890
6951
30.305156
-97.757721
1000
11
Jacksonville
Florida
880619
3791
30.293427
-81.617432
1000
12
San Francisco
California
870887
12910
37.760899
-122.436447
1000
13
Columbus
Ohio
860090
4806
40.011657
-82.998962
1000
14
Indianapolis
Indiana
855164
4731
39.806244
-86.138306
1000
15
Fort Worth
Texas
854113
7745
32.748999
-97.344197
1000
16
Charlotte
North Carolina
842051
5403
35.196082
-80.830536
1000
17
Seattle
Washington
704352
10932
47.625419
-122.335510
1000
18
Denver
Colorado
693060
9778
39.735524
-104.924271
999
19
El Paso
Texas
683080
2098
31.793389
-106.427307
1000
20
Washington
District of Columbia
681170
10108
38.911294
-77.030640
1000
21
Boston
Massachusetts
673184
8466
42.347842
-71.071243
1000
22
Detroit
Michigan
672795
9816
42.362419
-83.090973
1000
23
Nashville-Davidson
Tennessee
660388
4562
36.137698
-86.775513
1000
24
Memphis
Tennessee
652717
2938
35.130966
-90.014392
1000
25
Portland
Oregon
639863
9353
45.515785
-122.654114
1000
26
Oklahoma City
Oklahoma
638367
3331
35.490690
-97.539368
1000
27
Las Vegas
Nevada
632912
7531
36.135480
-115.193024
1000
28
Louisville-Jefferson County
Kentucky
616261
2981
38.225055
-85.676880
1000
29
Baltimore
Maryland
614664
4990
39.309286
-76.609039
1000
...
...
...
...
...
...
...
...
731
Pinellas Park
Florida
52137
1646
27.853960
-82.715086
1000
732
La Crosse
Wisconsin
52109
285
43.828448
-91.237434
285
733
Grapevine
Texas
51971
1265
32.933838
-97.076402
1000
734
Apple Valley
Minnesota
51957
92
44.798165
-93.206184
92
735
Tigard
Oregon
51902
1286
45.437133
-122.757415
1000
736
Glendora
California
51851
1806
34.126574
-117.858582
1000
737
Florissant
Missouri
51776
1940
38.797933
-90.340576
1000
738
Oak Park
Illinois
51774
3207
41.888031
-87.786386
1000
739
Hoffman Estates
Illinois
51738
3223
42.063522
-88.134371
1000
740
Kentwood
Michigan
51689
1456
42.909952
-85.607529
1000
741
Battle Creek
Michigan
51534
222
42.320535
-85.182921
222
742
Grand Island
Nebraska
51517
132
40.915836
-98.359566
132
743
Aliso Viejo
California
51424
691
33.574321
-117.713671
669
744
Edina
Minnesota
51350
1363
44.895375
-93.336635
1000
745
Olympia
Washington
51202
739
47.040136
-122.871574
737
746
Parker
Colorado
51163
502
39.537290
-104.772148
501
747
Enid
Oklahoma
51004
133
36.398615
-97.885430
133
748
Burien
Washington
50997
355
47.470249
-122.330817
355
749
Coral Gables
Florida
50815
3576
25.733129
-80.266800
1000
750
Logan
Utah
50676
211
41.745946
-111.832924
210
751
Plainfield
New Jersey
50636
323
40.620820
-74.424521
322
752
Cerritos
California
50555
4686
33.864797
-118.057160
1000
753
Galveston
Texas
50550
446
29.322228
-94.807205
446
754
Coeur d'Alene
Idaho
50285
322
47.704204
-116.780409
322
755
Lakewood
Ohio
50279
1124
41.483365
-81.797833
1000
756
Poway
California
50077
842
32.958939
-117.029167
827
757
Troy
New York
49702
1635
42.734863
-73.668823
1000
758
Charleston
West Virginia
49138
436
38.342749
-81.640091
436
759
Saginaw
Michigan
48984
362
43.446392
-83.983612
362
760
Niagara Falls
New York
48632
1645
43.093416
-78.986991
1000
761 rows × 7 columns
In [3]:
df_rest = pd.read_csv('df_restaurants.csv', index_col=0)
df_rest
Out[3]:
id
name
city
state
rating
review_count
cost
latitude
longitude
has_delivery
has_pickup
url
0
poquito-picante-brooklyn-2
Poquito Picante
New York
New York
4.5
40
2
40.685742
-73.981262
True
True
https://www.yelp.com/biz/poquito-picante-brook...
1
nourish-brooklyn-4
Nourish
New York
New York
4.0
65
2
40.677960
-73.968550
True
True
https://www.yelp.com/biz/nourish-brooklyn-4?ad...
2
taste-of-heaven-brooklyn
Taste of Heaven
New York
New York
5.0
19
2
40.717150
-73.940540
False
True
https://www.yelp.com/biz/taste-of-heaven-brook...
3
milk-and-cream-cereal-bar-new-york
Milk & Cream Cereal Bar
New York
New York
4.5
307
2
40.719580
-73.996540
False
False
https://www.yelp.com/biz/milk-and-cream-cereal...
4
the-bao-shoppe-new-york-2
The Bao Shoppe
New York
New York
4.0
99
1
40.714345
-73.990518
False
False
https://www.yelp.com/biz/the-bao-shoppe-new-yo...
5
breakroom-new-york
Breakroom
New York
New York
4.5
1237
1
40.716691
-73.999944
True
True
https://www.yelp.com/biz/breakroom-new-york?ad...
6
bulbap-grill-brooklyn
Bulbap Grill
New York
New York
4.5
73
2
40.724300
-73.950910
False
False
https://www.yelp.com/biz/bulbap-grill-brooklyn...
7
mysttik-masaala-queens-3
Mysttik Masaala
New York
New York
4.5
57
3
40.745787
-73.955732
False
False
https://www.yelp.com/biz/mysttik-masaala-queen...
8
burger-and-lobster-new-york
Burger & Lobster
New York
New York
4.0
3610
2
40.740160
-73.993372
False
False
https://www.yelp.com/biz/burger-and-lobster-ne...
9
char-sue-new-york
Char Sue
New York
New York
4.5
70
2
40.719600
-73.987915
True
True
https://www.yelp.com/biz/char-sue-new-york?adj...
10
wah-fung-no-1-new-york
Wah Fung No 1
New York
New York
4.5
789
1
40.717350
-73.994570
False
False
https://www.yelp.com/biz/wah-fung-no-1-new-yor...
11
honeygrow-brooklyn
honeygrow
New York
New York
4.0
53
2
40.692500
-73.991410
False
False
https://www.yelp.com/biz/honeygrow-brooklyn?ad...
12
rahi-new-york
Rahi
New York
New York
4.5
72
3
40.736027
-74.000544
False
False
https://www.yelp.com/biz/rahi-new-york?adjust_...
13
cheeky-sandwiches-new-york
Cheeky Sandwiches
New York
New York
4.5
917
1
40.715800
-73.991690
True
True
https://www.yelp.com/biz/cheeky-sandwiches-new...
14
2nd-city-new-york-4
2nd City
New York
New York
4.5
404
2
40.734050
-74.006420
False
True
https://www.yelp.com/biz/2nd-city-new-york-4?a...
15
out-east-new-york
Out East
New York
New York
4.0
50
3
40.725272
-73.983240
False
False
https://www.yelp.com/biz/out-east-new-york?adj...
16
pokébāb-brooklyn-2
Pokébāb
New York
New York
4.5
50
2
40.716830
-73.958660
False
False
https://www.yelp.com/biz/pok%C3%A9b%C4%81b-bro...
17
mysttik-masaala-new-york-15
Mysttik Masaala
New York
New York
4.5
69
3
40.755760
-73.975470
False
False
https://www.yelp.com/biz/mysttik-masaala-new-y...
18
los-tacos-no-1-new-york
Los Tacos No.1
New York
New York
4.5
1845
1
40.742555
-74.006084
False
False
https://www.yelp.com/biz/los-tacos-no-1-new-yo...
19
the-wei-brooklyn
The Wei
New York
New York
4.5
150
1
40.689830
-73.981710
False
True
https://www.yelp.com/biz/the-wei-brooklyn?adju...
20
julianas-pizza-brooklyn-5
Juliana's Pizza
New York
New York
4.5
1399
2
40.702615
-73.993416
False
False
https://www.yelp.com/biz/julianas-pizza-brookl...
21
lena-new-york
Lena
New York
New York
5.0
17
2
40.719110
-73.991600
False
True
https://www.yelp.com/biz/lena-new-york?adjust_...
22
miss-ada-brooklyn-2
Miss Ada
New York
New York
4.5
36
3
40.689436
-73.972381
False
False
https://www.yelp.com/biz/miss-ada-brooklyn-2?a...
23
fishmarket-restaurant-new-york
Fishmarket Restaurant
New York
New York
4.5
366
2
40.707170
-74.001920
False
False
https://www.yelp.com/biz/fishmarket-restaurant...
24
minnies-new-york
Minnie's
New York
New York
4.5
27
2
40.720450
-73.984480
False
False
https://www.yelp.com/biz/minnies-new-york?adju...
25
saigon-shack-new-york
Saigon Shack
New York
New York
4.0
1822
1
40.729690
-74.000629
False
False
https://www.yelp.com/biz/saigon-shack-new-york...
26
wafas-brooklyn-6
Wafa's
New York
New York
5.0
64
2
40.711712
-73.940941
False
True
https://www.yelp.com/biz/wafas-brooklyn-6?adju...
27
thursday-kitchen-new-york
Thursday Kitchen
New York
New York
4.5
534
2
40.727500
-73.983800
False
False
https://www.yelp.com/biz/thursday-kitchen-new-...
28
hole-in-the-wall-new-york-2
Hole in the Wall
New York
New York
4.5
102
2
40.708370
-74.005630
False
False
https://www.yelp.com/biz/hole-in-the-wall-new-...
29
rice-and-miso-brooklyn
Rice & Miso
New York
New York
4.5
22
2
40.684544
-73.983778
False
False
https://www.yelp.com/biz/rice-and-miso-brookly...
...
...
...
...
...
...
...
...
...
...
...
...
...
621921
al-salam-market-and-grill-buffalo
Al-Salam Market & Grill
Niagara Falls
New York
3.0
8
1
42.958859
-78.878258
False
False
https://www.yelp.com/biz/al-salam-market-and-g...
621922
petes-lebanese-bakery-buffalo
Pete's Lebanese Bakery
Niagara Falls
New York
4.5
7
1
42.964418
-78.878855
False
False
https://www.yelp.com/biz/petes-lebanese-bakery...
621923
leonardis-pizzeria-buffalo-3
Leonardi's Pizzeria
Niagara Falls
New York
4.0
70
2
42.971481
-78.806774
False
False
https://www.yelp.com/biz/leonardis-pizzeria-bu...
621924
super-submarine-niagara-falls
Super Submarine
Niagara Falls
New York
4.0
4
3
43.070060
-79.113960
False
False
https://www.yelp.com/biz/super-submarine-niaga...
621925
the-shores-waterfront-restaurant-north-tonawanda
The Shores Waterfront Restaurant
Niagara Falls
New York
3.0
36
2
43.024550
-78.885870
False
False
https://www.yelp.com/biz/the-shores-waterfront...
621926
l-and-j-deli-niagara-falls
L & J Deli
Niagara Falls
New York
5.0
1
3
43.069540
-79.134760
False
False
https://www.yelp.com/biz/l-and-j-deli-niagara-...
621927
cafe-banchetti-buffalo
Cafe Banchetti
Niagara Falls
New York
4.0
2
1
43.034820
-78.803900
False
False
https://www.yelp.com/biz/cafe-banchetti-buffal...
621928
rite-aid-grand-island-2
Rite Aid
Niagara Falls
New York
5.0
1
3
43.025213
-78.964877
False
False
https://www.yelp.com/biz/rite-aid-grand-island...
621929
mcmahon-day-by-day-family-restaurant-grand-isl...
McMahon Day by Day Family Restaurant
Niagara Falls
New York
2.5
16
1
43.012320
-78.953220
False
False
https://www.yelp.com/biz/mcmahon-day-by-day-fa...
621930
caramicis-bakery-amherst
Caramici's Bakery
Niagara Falls
New York
5.0
9
2
42.973353
-78.822670
False
False
https://www.yelp.com/biz/caramicis-bakery-amhe...
621931
la-pizza-club-buffalo
La Pizza Club
Niagara Falls
New York
3.5
20
1
42.947441
-78.851974
False
False
https://www.yelp.com/biz/la-pizza-club-buffalo...
621932
7-eleven-kenmore
7-Eleven
Niagara Falls
New York
3.0
3
2
42.981479
-78.879182
False
False
https://www.yelp.com/biz/7-eleven-kenmore?adju...
621933
cc-swirls-niagara-falls
CC Swirls
Niagara Falls
New York
5.0
5
2
43.089375
-79.127812
False
False
https://www.yelp.com/biz/cc-swirls-niagara-fal...
621934
carlas-crumbly-creations-north-tonawanda
Carla's Crumbly Creations
Niagara Falls
New York
4.5
2
3
43.034862
-78.871166
False
False
https://www.yelp.com/biz/carlas-crumbly-creati...
621935
golden-steer-dining-lounge-and-family-restaura...
Golden Steer Dining Lounge & Family Restaurant
Niagara Falls
New York
4.0
1
3
43.093254
-79.077744
False
False
https://www.yelp.com/biz/golden-steer-dining-l...
621936
mrs-thank-you-lewiston
Mrs Thank You
Niagara Falls
New York
1.0
2
1
43.166473
-79.002018
False
False
https://www.yelp.com/biz/mrs-thank-you-lewisto...
621937
sugarbox-tonawanda
SugarBox
Niagara Falls
New York
4.0
1
3
43.033977
-78.870713
False
False
https://www.yelp.com/biz/sugarbox-tonawanda?ad...
621938
ihop-niagara-falls-2
IHOP
Niagara Falls
New York
2.5
36
2
43.088260
-79.121920
False
False
https://www.yelp.com/biz/ihop-niagara-falls-2?...
621939
boardwalk-bar-and-grill-grand-island
Boardwalk Bar and Grill
Niagara Falls
New York
3.5
4
2
42.960433
-78.950557
False
False
https://www.yelp.com/biz/boardwalk-bar-and-gri...
621940
niagara-oast-house-brewers-niagara-on-the-lake
Niagara Oast House Brewers
Niagara Falls
New York
4.5
30
2
43.240114
-79.098920
False
False
https://www.yelp.com/biz/niagara-oast-house-br...
621941
donnellys-irish-pub-thorold
Donnelly's Irish Pub
Niagara Falls
New York
5.0
2
3
43.123383
-79.200455
False
False
https://www.yelp.com/biz/donnellys-irish-pub-t...
621942
china-max-buffalo
China Max
Niagara Falls
New York
4.0
20
1
42.972580
-78.822850
True
True
https://www.yelp.com/biz/china-max-buffalo?adj...
621943
lucys-kitchen-buffalo
Lucy's kitchen
Niagara Falls
New York
5.0
2
3
42.952160
-78.904853
False
False
https://www.yelp.com/biz/lucys-kitchen-buffalo...
621944
rolling-cannoli-buffalo
Rolling Cannoli
Niagara Falls
New York
5.0
1
1
42.980608
-78.846265
False
False
https://www.yelp.com/biz/rolling-cannoli-buffa...
621945
francos-pizza-tonawanda-2
Franco's Pizza
Niagara Falls
New York
3.5
21
1
43.017212
-78.822322
False
False
https://www.yelp.com/biz/francos-pizza-tonawan...
621946
newroz-market-and-grill-buffalo-2
Newroz Market & Grill
Niagara Falls
New York
4.0
8
2
42.947540
-78.864555
False
False
https://www.yelp.com/biz/newroz-market-and-gri...
621947
go-veggies-tonawanda
Go Veggies
Niagara Falls
New York
4.5
5
3
42.981113
-78.886391
True
True
https://www.yelp.com/biz/go-veggies-tonawanda?...
621948
tim-hortons-buffalo-27
Tim Hortons
Niagara Falls
New York
3.5
14
1
42.956928
-78.878756
False
False
https://www.yelp.com/biz/tim-hortons-buffalo-2...
621949
tim-hortons-niagara-falls-6
Tim Hortons
Niagara Falls
New York
3.0
8
1
43.098430
-79.086140
False
False
https://www.yelp.com/biz/tim-hortons-niagara-f...
621950
mister-softee-buffalo
Mister Softee
Niagara Falls
New York
2.5
2
3
42.953279
-78.893563
False
False
https://www.yelp.com/biz/mister-softee-buffalo...
621951 rows × 12 columns
In [4]:
# load pickle here
df_cats = pd.read_pickle('df_categories_sparse.pkl')
df_cats = df_cats.to_sparse()
In [5]:
df_cats_info = pd.read_json('categories.json')
df_cats_info
Out[5]:
alias
country_blacklist
country_whitelist
parents
title
0
3dprinting
NaN
NaN
[localservices]
3D Printing
1
abruzzese
NaN
[IT]
[italian]
Abruzzese
2
absinthebars
NaN
[CZ]
[bars]
Absinthe Bars
3
acaibowls
[AR, PL, TR, MX, CL, IT]
NaN
[food]
Acai Bowls
4
accessories
NaN
NaN
[fashion]
Accessories
5
accountants
NaN
NaN
[professional]
Accountants
6
acnetreatment
NaN
NaN
[beautysvc]
Acne Treatment
7
active
NaN
NaN
[]
Active Life
8
acupuncture
NaN
NaN
[health]
Acupuncture
9
addictionmedicine
[JP]
NaN
[physicians]
Addiction Medicine
10
adoptionservices
NaN
NaN
[localservices]
Adoption Services
11
adult
NaN
NaN
[shopping]
Adult
12
adultedu
NaN
NaN
[education]
Adult Education
13
adultentertainment
NaN
NaN
[nightlife]
Adult Entertainment
14
advertising
NaN
NaN
[professional]
Advertising
15
aerialfitness
NaN
NaN
[fitness]
Aerial Fitness
16
aerialtours
NaN
NaN
[tours]
Aerial Tours
17
afghani
[TR, MX]
NaN
[restaurants]
Afghan
18
african
[TR]
NaN
[restaurants]
African
19
afrobrazilian
NaN
[BR]
[religiousorgs]
Afro-Brazilian
20
agriturismi
NaN
[PL, CH, MX, FR, ES, CL, IT, AR, AT, CZ, DE, TW]
[hotels]
Agriturismi
21
aircraftdealers
NaN
[US, PT, CZ]
[auto]
Aircraft Dealers
22
aircraftrepairs
NaN
NaN
[auto]
Aircraft Repairs
23
airductcleaning
NaN
[US, ES, IT]
[localservices]
Air Duct Cleaning
24
airlines
NaN
NaN
[transport]
Airlines
25
airport_shuttles
NaN
NaN
[transport]
Airport Shuttles
26
airportlounges
NaN
NaN
[bars]
Airport Lounges
27
airports
NaN
NaN
[hotelstravel]
Airports
28
airportterminals
NaN
NaN
[airports]
Airport Terminals
29
airsoft
NaN
NaN
[active]
Airsoft
...
...
...
...
...
...
1483
wholesale_stores
[AT, CH, DE]
NaN
[shopping]
Wholesale Stores
1484
wholesalers
[TR, PH, FR, MY, FI, CA, GB, TW, HK, BR, NZ, I...
NaN
[professional]
Wholesalers
1485
wigs
[TR, BR, CH, PH, MY, JP, NZ, IE, AT, SE, SG, G...
NaN
[shopping]
Wigs
1486
wildlifecontrol
[JP]
NaN
[localservices]
Wildlife Control
1487
wildlifehunting
NaN
[US]
[active]
Wildlife Hunting Ranges
1488
willstrustsprobates
NaN
[SG, US, AU, NL, IT]
[estateplanning]
Wills, Trusts, & Probates
1489
windowsinstallation
NaN
NaN
[homeservices]
Windows Installation
1490
windowwashing
NaN
NaN
[homeservices]
Window Washing
1491
windshieldinstallrepair
[AT, CH, DE, CZ]
NaN
[auto]
Windshield Installation & Repair
1492
wine_bars
NaN
NaN
[bars]
Wine Bars
1493
wineries
[FI]
NaN
[arts, food]
Wineries
1494
winetasteclasses
NaN
NaN
[tastingclasses]
Wine Tasting Classes
1495
winetastingroom
NaN
NaN
[wineries]
Wine Tasting Room
1496
winetours
NaN
NaN
[tours]
Wine Tours
1497
wok
[PL, TR, GB, BR, JP, US, NZ, IE, IT, AR, CA, S...
NaN
[restaurants]
Wok
1498
womenscloth
NaN
NaN
[fashion]
Women's Clothing
1499
workerscomplaw
[AT, FR, CH, DE]
NaN
[lawyers]
Workers Compensation Law
1500
wraps
NaN
[TR, PT, SE, CZ, DK, US, NO]
[restaurants]
Wraps
1501
xmasmarkets
[TR, CA, BR, SG, US, NZ, IE]
NaN
[festivals]
Christmas Markets
1502
yakiniku
NaN
[TW, SG, JP]
[japanese]
Yakiniku
1503
yakitori
NaN
[TW, SG, JP]
[japanese]
Yakitori
1504
yelpevents
NaN
NaN
[localflavor]
Yelp Events
1505
yoga
NaN
NaN
[fitness]
Yoga
1506
youth_club
NaN
[CH, FR, FI, NO, IT, PT, SE, CZ, DE, DK, AU, N...
[localservices]
Youth Club
1507
yucatan
NaN
[MX]
[mexican]
Yucatan
1508
yugoslav
NaN
[PT, SE, FR, AU, BE, IT]
[restaurants]
Yugoslav
1509
zapiekanka
NaN
[PL]
[food]
Zapiekanka
1510
zipline
NaN
NaN
[active]
Ziplining
1511
zoos
NaN
NaN
[active]
Zoos
1512
zorbing
NaN
[PT, MX, CZ, ES, US, NZ]
[active]
Zorbing
1513 rows × 5 columns
In [6]:
val_counts_dict = {t: df_rest.loc[df_cats[t]==1].shape[0] for t in df_cats.columns}
In [7]:
pd.DataFrame.from_dict([val_counts_dict]).T.sort_values(0, ascending=False)
Out[7]:
0
sandwiches
64723
mexican
62550
hotdogs
58303
tradamerican
52656
pizza
50188
burgers
48277
breakfast_brunch
39025
newamerican
31026
coffee
29987
italian
28380
seafood
26280
chinese
26267
grocery
22727
salad
22291
bakeries
20171
bars
19994
foodtrucks
19650
chicken_wings
17667
japanese
16973
delis
16854
sushi
16021
catering
15751
desserts
15228
icecream
15182
bbq
15170
convenience
14308
cafes
14229
asianfusion
12304
mediterranean
11744
sportsbars
11618
...
...
isps
1
sommelierservices
1
clothingrental
1
autopartssupplies
1
mailboxcenters
1
homeappliancerepair
1
baseballfields
1
tableware
1
bespoke
1
travelagents
1
races
1
tradclothing
1
grillingequipment
1
realestate
1
guitarstores
1
gun_ranges
1
massmedia
1
martialarts
1
halotherapy
1
hats
1
hearingaidproviders
1
artschools
1
marketing
1
saunas
1
artsupplies
1
screenprinting
1
computers
1
tamales
1
holidaydecorations
1
clowns
1
684 rows × 1 columns
In [8]:
df_cats.loc[(df_cats['sandwiches']==1) & (df_cats['hotdogs']==1)].shape
Out[8]:
(13856, 684)
In [9]:
df_hist = pd.DataFrame()
df_hist['hotdog_and_sandwich'] = (df_rest.loc[(df_cats['sandwiches']==1) &
((df_cats['hotdogs']==1) |
(df_cats['hotdogs']==1)), 'rating']
.value_counts()
.sort_index())
df_hist['hotdog_only'] = (df_rest.loc[(df_cats['sandwiches']==0) &
((df_cats['hotdogs']==1) |
(df_cats['hotdogs']==1)), 'rating']
.value_counts()
.sort_index())
df_hist['sandwich_only'] = (df_rest.loc[(df_cats['sandwiches']==1) &
((df_cats['hotdogs']==0) &
(df_cats['hotdogs']==0)), 'rating']
.value_counts()
.sort_index())
df_hist['field'] = (df_rest.loc[(df_cats['sandwiches']==0) &
((df_cats['hotdogs']==0) &
(df_cats['hotdogs']==0)), 'rating']
.value_counts()
.sort_index())
df_hist
Out[9]:
hotdog_and_sandwich
hotdog_only
sandwich_only
field
1.0
939
2177
316
7835
1.5
517
3346
280
3949
2.0
1384
5888
928
11775
2.5
1752
7180
2348
23704
3.0
2406
7768
5182
54017
3.5
2434
7047
9626
96859
4.0
2506
7056
16488
158139
4.5
953
2926
12473
101308
5.0
965
1057
3224
55185
In [10]:
for col in df_hist.columns:
df_hist[col] = df_hist[col]/df_hist[col].sum()
In [11]:
df_hist['rating'] = df_hist.index
In [12]:
df_hist = pd.melt(df_hist, id_vars='rating')
In [13]:
sns.barplot(y='value', x='rating', data=df_hist, hue='variable')
plt.xticks(rotation=90)
plt.show()
In [14]:
df_rest.loc[(df_rest.loc[(df_cats['icecream']==1) &
((df_cats['hotdogs']==1) |
(df_cats['hotdogs']==1))].index),
'icedog'] = 'hotdog_and_icecream'
In [15]:
df_rest = df_rest.reset_index(drop=True)
In [16]:
df_rest.loc[(df_cats['icecream']==0) &
((df_cats['hotdog']==0) &
(df_cats['hotdogs']==0))]
Out[16]:
id
name
city
state
rating
review_count
cost
latitude
longitude
has_delivery
has_pickup
url
icedog
0
poquito-picante-brooklyn-2
Poquito Picante
New York
New York
4.5
40
2
40.685742
-73.981262
True
True
https://www.yelp.com/biz/poquito-picante-brook...
NaN
1
nourish-brooklyn-4
Nourish
New York
New York
4.0
65
2
40.677960
-73.968550
True
True
https://www.yelp.com/biz/nourish-brooklyn-4?ad...
NaN
2
taste-of-heaven-brooklyn
Taste of Heaven
New York
New York
5.0
19
2
40.717150
-73.940540
False
True
https://www.yelp.com/biz/taste-of-heaven-brook...
NaN
4
the-bao-shoppe-new-york-2
The Bao Shoppe
New York
New York
4.0
99
1
40.714345
-73.990518
False
False
https://www.yelp.com/biz/the-bao-shoppe-new-yo...
NaN
5
breakroom-new-york
Breakroom
New York
New York
4.5
1237
1
40.716691
-73.999944
True
True
https://www.yelp.com/biz/breakroom-new-york?ad...
NaN
6
bulbap-grill-brooklyn
Bulbap Grill
New York
New York
4.5
73
2
40.724300
-73.950910
False
False
https://www.yelp.com/biz/bulbap-grill-brooklyn...
NaN
7
mysttik-masaala-queens-3
Mysttik Masaala
New York
New York
4.5
57
3
40.745787
-73.955732
False
False
https://www.yelp.com/biz/mysttik-masaala-queen...
NaN
8
burger-and-lobster-new-york
Burger & Lobster
New York
New York
4.0
3610
2
40.740160
-73.993372
False
False
https://www.yelp.com/biz/burger-and-lobster-ne...
NaN
9
char-sue-new-york
Char Sue
New York
New York
4.5
70
2
40.719600
-73.987915
True
True
https://www.yelp.com/biz/char-sue-new-york?adj...
NaN
11
honeygrow-brooklyn
honeygrow
New York
New York
4.0
53
2
40.692500
-73.991410
False
False
https://www.yelp.com/biz/honeygrow-brooklyn?ad...
NaN
12
rahi-new-york
Rahi
New York
New York
4.5
72
3
40.736027
-74.000544
False
False
https://www.yelp.com/biz/rahi-new-york?adjust_...
NaN
13
cheeky-sandwiches-new-york
Cheeky Sandwiches
New York
New York
4.5
917
1
40.715800
-73.991690
True
True
https://www.yelp.com/biz/cheeky-sandwiches-new...
NaN
14
2nd-city-new-york-4
2nd City
New York
New York
4.5
404
2
40.734050
-74.006420
False
True
https://www.yelp.com/biz/2nd-city-new-york-4?a...
NaN
15
out-east-new-york
Out East
New York
New York
4.0
50
3
40.725272
-73.983240
False
False
https://www.yelp.com/biz/out-east-new-york?adj...
NaN
16
pokébāb-brooklyn-2
Pokébāb
New York
New York
4.5
50
2
40.716830
-73.958660
False
False
https://www.yelp.com/biz/pok%C3%A9b%C4%81b-bro...
NaN
17
mysttik-masaala-new-york-15
Mysttik Masaala
New York
New York
4.5
69
3
40.755760
-73.975470
False
False
https://www.yelp.com/biz/mysttik-masaala-new-y...
NaN
18
los-tacos-no-1-new-york
Los Tacos No.1
New York
New York
4.5
1845
1
40.742555
-74.006084
False
False
https://www.yelp.com/biz/los-tacos-no-1-new-yo...
NaN
19
the-wei-brooklyn
The Wei
New York
New York
4.5
150
1
40.689830
-73.981710
False
True
https://www.yelp.com/biz/the-wei-brooklyn?adju...
NaN
20
julianas-pizza-brooklyn-5
Juliana's Pizza
New York
New York
4.5
1399
2
40.702615
-73.993416
False
False
https://www.yelp.com/biz/julianas-pizza-brookl...
NaN
21
lena-new-york
Lena
New York
New York
5.0
17
2
40.719110
-73.991600
False
True
https://www.yelp.com/biz/lena-new-york?adjust_...
NaN
22
miss-ada-brooklyn-2
Miss Ada
New York
New York
4.5
36
3
40.689436
-73.972381
False
False
https://www.yelp.com/biz/miss-ada-brooklyn-2?a...
NaN
23
fishmarket-restaurant-new-york
Fishmarket Restaurant
New York
New York
4.5
366
2
40.707170
-74.001920
False
False
https://www.yelp.com/biz/fishmarket-restaurant...
NaN
24
minnies-new-york
Minnie's
New York
New York
4.5
27
2
40.720450
-73.984480
False
False
https://www.yelp.com/biz/minnies-new-york?adju...
NaN
25
saigon-shack-new-york
Saigon Shack
New York
New York
4.0
1822
1
40.729690
-74.000629
False
False
https://www.yelp.com/biz/saigon-shack-new-york...
NaN
26
wafas-brooklyn-6
Wafa's
New York
New York
5.0
64
2
40.711712
-73.940941
False
True
https://www.yelp.com/biz/wafas-brooklyn-6?adju...
NaN
27
thursday-kitchen-new-york
Thursday Kitchen
New York
New York
4.5
534
2
40.727500
-73.983800
False
False
https://www.yelp.com/biz/thursday-kitchen-new-...
NaN
28
hole-in-the-wall-new-york-2
Hole in the Wall
New York
New York
4.5
102
2
40.708370
-74.005630
False
False
https://www.yelp.com/biz/hole-in-the-wall-new-...
NaN
29
rice-and-miso-brooklyn
Rice & Miso
New York
New York
4.5
22
2
40.684544
-73.983778
False
False
https://www.yelp.com/biz/rice-and-miso-brookly...
NaN
30
l-e-s-kitchen-new-york
L.E.S Kitchen
New York
New York
4.0
299
1
40.715178
-73.990095
False
True
https://www.yelp.com/biz/l-e-s-kitchen-new-yor...
NaN
31
avocaderia-brooklyn
Avocaderia
New York
New York
4.0
91
2
40.656020
-74.007420
False
False
https://www.yelp.com/biz/avocaderia-brooklyn?a...
NaN
...
...
...
...
...
...
...
...
...
...
...
...
...
...
621917
pizza-pizza-niagara-falls
Pizza Pizza
Niagara Falls
New York
3.0
7
2
43.089704
-79.098111
False
False
https://www.yelp.com/biz/pizza-pizza-niagara-f...
NaN
621918
palumbos-pizza-tonawanda-2
Palumbo's Pizza
Niagara Falls
New York
4.5
6
1
42.980409
-78.894924
False
False
https://www.yelp.com/biz/palumbos-pizza-tonawa...
NaN
621921
al-salam-market-and-grill-buffalo
Al-Salam Market & Grill
Niagara Falls
New York
3.0
8
1
42.958859
-78.878258
False
False
https://www.yelp.com/biz/al-salam-market-and-g...
NaN
621922
petes-lebanese-bakery-buffalo
Pete's Lebanese Bakery
Niagara Falls
New York
4.5
7
1
42.964418
-78.878855
False
False
https://www.yelp.com/biz/petes-lebanese-bakery...
NaN
621923
leonardis-pizzeria-buffalo-3
Leonardi's Pizzeria
Niagara Falls
New York
4.0
70
2
42.971481
-78.806774
False
False
https://www.yelp.com/biz/leonardis-pizzeria-bu...
NaN
621925
the-shores-waterfront-restaurant-north-tonawanda
The Shores Waterfront Restaurant
Niagara Falls
New York
3.0
36
2
43.024550
-78.885870
False
False
https://www.yelp.com/biz/the-shores-waterfront...
NaN
621926
l-and-j-deli-niagara-falls
L & J Deli
Niagara Falls
New York
5.0
1
3
43.069540
-79.134760
False
False
https://www.yelp.com/biz/l-and-j-deli-niagara-...
NaN
621927
cafe-banchetti-buffalo
Cafe Banchetti
Niagara Falls
New York
4.0
2
1
43.034820
-78.803900
False
False
https://www.yelp.com/biz/cafe-banchetti-buffal...
NaN
621928
rite-aid-grand-island-2
Rite Aid
Niagara Falls
New York
5.0
1
3
43.025213
-78.964877
False
False
https://www.yelp.com/biz/rite-aid-grand-island...
NaN
621929
mcmahon-day-by-day-family-restaurant-grand-isl...
McMahon Day by Day Family Restaurant
Niagara Falls
New York
2.5
16
1
43.012320
-78.953220
False
False
https://www.yelp.com/biz/mcmahon-day-by-day-fa...
NaN
621930
caramicis-bakery-amherst
Caramici's Bakery
Niagara Falls
New York
5.0
9
2
42.973353
-78.822670
False
False
https://www.yelp.com/biz/caramicis-bakery-amhe...
NaN
621931
la-pizza-club-buffalo
La Pizza Club
Niagara Falls
New York
3.5
20
1
42.947441
-78.851974
False
False
https://www.yelp.com/biz/la-pizza-club-buffalo...
NaN
621932
7-eleven-kenmore
7-Eleven
Niagara Falls
New York
3.0
3
2
42.981479
-78.879182
False
False
https://www.yelp.com/biz/7-eleven-kenmore?adju...
NaN
621933
cc-swirls-niagara-falls
CC Swirls
Niagara Falls
New York
5.0
5
2
43.089375
-79.127812
False
False
https://www.yelp.com/biz/cc-swirls-niagara-fal...
NaN
621934
carlas-crumbly-creations-north-tonawanda
Carla's Crumbly Creations
Niagara Falls
New York
4.5
2
3
43.034862
-78.871166
False
False
https://www.yelp.com/biz/carlas-crumbly-creati...
NaN
621935
golden-steer-dining-lounge-and-family-restaura...
Golden Steer Dining Lounge & Family Restaurant
Niagara Falls
New York
4.0
1
3
43.093254
-79.077744
False
False
https://www.yelp.com/biz/golden-steer-dining-l...
NaN
621936
mrs-thank-you-lewiston
Mrs Thank You
Niagara Falls
New York
1.0
2
1
43.166473
-79.002018
False
False
https://www.yelp.com/biz/mrs-thank-you-lewisto...
NaN
621937
sugarbox-tonawanda
SugarBox
Niagara Falls
New York
4.0
1
3
43.033977
-78.870713
False
False
https://www.yelp.com/biz/sugarbox-tonawanda?ad...
NaN
621938
ihop-niagara-falls-2
IHOP
Niagara Falls
New York
2.5
36
2
43.088260
-79.121920
False
False
https://www.yelp.com/biz/ihop-niagara-falls-2?...
NaN
621939
boardwalk-bar-and-grill-grand-island
Boardwalk Bar and Grill
Niagara Falls
New York
3.5
4
2
42.960433
-78.950557
False
False
https://www.yelp.com/biz/boardwalk-bar-and-gri...
NaN
621940
niagara-oast-house-brewers-niagara-on-the-lake
Niagara Oast House Brewers
Niagara Falls
New York
4.5
30
2
43.240114
-79.098920
False
False
https://www.yelp.com/biz/niagara-oast-house-br...
NaN
621941
donnellys-irish-pub-thorold
Donnelly's Irish Pub
Niagara Falls
New York
5.0
2
3
43.123383
-79.200455
False
False
https://www.yelp.com/biz/donnellys-irish-pub-t...
NaN
621942
china-max-buffalo
China Max
Niagara Falls
New York
4.0
20
1
42.972580
-78.822850
True
True
https://www.yelp.com/biz/china-max-buffalo?adj...
NaN
621943
lucys-kitchen-buffalo
Lucy's kitchen
Niagara Falls
New York
5.0
2
3
42.952160
-78.904853
False
False
https://www.yelp.com/biz/lucys-kitchen-buffalo...
NaN
621944
rolling-cannoli-buffalo
Rolling Cannoli
Niagara Falls
New York
5.0
1
1
42.980608
-78.846265
False
False
https://www.yelp.com/biz/rolling-cannoli-buffa...
NaN
621945
francos-pizza-tonawanda-2
Franco's Pizza
Niagara Falls
New York
3.5
21
1
43.017212
-78.822322
False
False
https://www.yelp.com/biz/francos-pizza-tonawan...
NaN
621946
newroz-market-and-grill-buffalo-2
Newroz Market & Grill
Niagara Falls
New York
4.0
8
2
42.947540
-78.864555
False
False
https://www.yelp.com/biz/newroz-market-and-gri...
NaN
621947
go-veggies-tonawanda
Go Veggies
Niagara Falls
New York
4.5
5
3
42.981113
-78.886391
True
True
https://www.yelp.com/biz/go-veggies-tonawanda?...
NaN
621948
tim-hortons-buffalo-27
Tim Hortons
Niagara Falls
New York
3.5
14
1
42.956928
-78.878756
False
False
https://www.yelp.com/biz/tim-hortons-buffalo-2...
NaN
621949
tim-hortons-niagara-falls-6
Tim Hortons
Niagara Falls
New York
3.0
8
1
43.098430
-79.086140
False
False
https://www.yelp.com/biz/tim-hortons-niagara-f...
NaN
544910 rows × 13 columns
In [17]:
df_rest.loc[(df_cats['icecream']==1) &
((df_cats['hotdog']==0) &
(df_cats['hotdogs']==0))]
Out[17]:
id
name
city
state
rating
review_count
cost
latitude
longitude
has_delivery
has_pickup
url
icedog
3
milk-and-cream-cereal-bar-new-york
Milk & Cream Cereal Bar
New York
New York
4.5
307
2
40.719580
-73.996540
False
False
https://www.yelp.com/biz/milk-and-cream-cereal...
NaN
75
by-chloe-new-york-11
by CHLOE
New York
New York
4.0
1275
2
40.729242
-74.000913
False
False
https://www.yelp.com/biz/by-chloe-new-york-11?...
NaN
128
by-chloe-soho-new-york
by CHLOE - Soho
New York
New York
4.0
119
2
40.722770
-73.997200
False
False
https://www.yelp.com/biz/by-chloe-soho-new-yor...
NaN
228
shake-shack-new-york-11
Shake Shack
New York
New York
4.0
802
2
40.715317
-74.014809
False
False
https://www.yelp.com/biz/shake-shack-new-york-...
NaN
470
shake-shack-brooklyn-12
Shake Shack
New York
New York
4.0
260
2
40.703015
-73.993954
False
False
https://www.yelp.com/biz/shake-shack-brooklyn-...
NaN
547
shake-shack-brooklyn
Shake Shack
New York
New York
4.0
733
2
40.692088
-73.988869
False
False
https://www.yelp.com/biz/shake-shack-brooklyn?...
NaN
697
mister-dips-brooklyn
Mister Dips
New York
New York
4.0
51
2
40.722280
-73.957121
False
False
https://www.yelp.com/biz/mister-dips-brooklyn?...
NaN
824
brooklyn-farmacy-and-soda-fountain-brooklyn
Brooklyn Farmacy & Soda Fountain
New York
New York
4.0
556
2
40.683980
-73.999230
False
False
https://www.yelp.com/biz/brooklyn-farmacy-and-...
NaN
975
shake-shack-new-york-34
Shake Shack
New York
New York
4.0
154
2
40.751171
-73.988136
False
False
https://www.yelp.com/biz/shake-shack-new-york-...
NaN
1360
zeros-unlikely-snacks-los-angeles
Zero's Unlikely Snacks
Los Angeles
California
5.0
12
1
34.100755
-118.273439
False
False
https://www.yelp.com/biz/zeros-unlikely-snacks...
NaN
1464
snow-monster-los-angeles-11
Snow Monster
Los Angeles
California
4.0
241
1
34.063735
-118.297312
False
False
https://www.yelp.com/biz/snow-monster-los-ange...
NaN
1753
news-donuts-ice-cream-and-coffee-los-angeles
New's Donuts Ice Cream & Coffee
Los Angeles
California
4.5
19
1
34.047305
-118.317030
False
True
https://www.yelp.com/biz/news-donuts-ice-cream...
NaN
2084
joey-gs-mac-and-cheese-chicago
Joey G's Mac & Cheese
Chicago
Illinois
4.5
21
2
41.899232
-87.685849
False
False
https://www.yelp.com/biz/joey-gs-mac-and-chees...
NaN
2141
bistro-6050-chicago-2
Bistro 6050
Chicago
Illinois
5.0
61
1
41.953126
-87.778703
False
True
https://www.yelp.com/biz/bistro-6050-chicago-2...
NaN
2142
the-fat-shallot-chicago-6
The Fat Shallot
Chicago
Illinois
5.0
4
3
41.879790
-87.630510
False
False
https://www.yelp.com/biz/the-fat-shallot-chica...
NaN
2616
shake-shack-chicago-2
Shake Shack
Chicago
Illinois
3.5
389
2
41.881664
-87.624969
False
False
https://www.yelp.com/biz/shake-shack-chicago-2...
NaN
2777
ice-max-chicago
Ice Max
Chicago
Illinois
4.5
39
1
41.852090
-87.631640
False
False
https://www.yelp.com/biz/ice-max-chicago?adjus...
NaN
2808
ice-max-chicago
Ice Max
Chicago
Illinois
4.5
39
1
41.852090
-87.631640
False
False
https://www.yelp.com/biz/ice-max-chicago?adjus...
NaN
2950
the-freeze-chicago
The Freeze
Chicago
Illinois
4.0
175
1
41.917343
-87.697879
False
False
https://www.yelp.com/biz/the-freeze-chicago?ad...
NaN
3201
treats-of-mexico-houston
Treats of Mexico
Houston
Texas
5.0
21
1
29.734550
-95.330940
False
False
https://www.yelp.com/biz/treats-of-mexico-hous...
NaN
3308
the-doughcone-houston-2
The DoughCone
Houston
Texas
4.5
95
1
29.715174
-95.418315
False
False
https://www.yelp.com/biz/the-doughcone-houston...
NaN
3319
el-rolis-bites-houston
El Roli's Bites
Houston
Texas
4.5
16
1
29.701477
-95.649733
False
False
https://www.yelp.com/biz/el-rolis-bites-housto...
NaN
3407
moooseum-ice-cream-houston
Moooseum Ice Cream
Houston
Texas
4.5
2
3
29.765260
-95.365670
False
False
https://www.yelp.com/biz/moooseum-ice-cream-ho...
NaN
3494
smoosh-cookies-houston
SMOOSH Cookies
Houston
Texas
4.5
170
1
29.715630
-95.414897
False
False
https://www.yelp.com/biz/smoosh-cookies-housto...
NaN
3534
yeti-sunshine-houston
Yeti Sunshine
Houston
Texas
4.5
37
1
29.760193
-95.369390
False
False
https://www.yelp.com/biz/yeti-sunshine-houston...
NaN
3673
nosh-houston-2
Nosh
Houston
Texas
3.5
20
2
29.757990
-95.366010
False
False
https://www.yelp.com/biz/nosh-houston-2?adjust...
NaN
3768
froeschls-ice-cream-houston
Froeschl's Ice Cream
Houston
Texas
5.0
4
1
29.760427
-95.369803
False
False
https://www.yelp.com/biz/froeschls-ice-cream-h...
NaN
4050
novel-ice-cream-phoenix
Novel Ice Cream
Phoenix
Arizona
5.0
84
1
33.455422
-112.086610
False
False
https://www.yelp.com/biz/novel-ice-cream-phoen...
NaN
4236
macalpines-diner-and-soda-fountain-phoenix
MacAlpine's Diner & Soda Fountain
Phoenix
Arizona
4.0
299
1
33.473161
-112.064955
False
False
https://www.yelp.com/biz/macalpines-diner-and-...
NaN
4401
fried-ice-and-bubble-tea-phoenix
Fried Ice & Bubble Tea
Phoenix
Arizona
4.0
51
1
33.509013
-112.048410
False
False
https://www.yelp.com/biz/fried-ice-and-bubble-...
NaN
...
...
...
...
...
...
...
...
...
...
...
...
...
...
620883
tiny-apple-store-bay-city
Tiny Apple Store
Saginaw
Michigan
5.0
7
3
43.578945
-83.962173
False
False
https://www.yelp.com/biz/tiny-apple-store-bay-...
NaN
620893
jamies-dippy-whip-bay-city
Jamie's Dippy Whip
Saginaw
Michigan
4.0
1
3
43.589138
-83.879005
False
False
https://www.yelp.com/biz/jamies-dippy-whip-bay...
NaN
620921
j-and-bs-sundaes-bridgeport-charter-township
J & B's Sundaes
Saginaw
Michigan
4.5
2
1
43.358898
-83.880684
False
False
https://www.yelp.com/biz/j-and-bs-sundaes-brid...
NaN
621013
de-dees-dairy-niagara-falls
De Dee's Dairy
Niagara Falls
New York
4.5
53
1
43.090976
-78.963650
False
False
https://www.yelp.com/biz/de-dees-dairy-niagara...
NaN
621161
menchies-frozen-yogurt-niagara-falls
Menchie's Frozen Yogurt
Niagara Falls
New York
5.0
9
1
43.093979
-78.971970
False
False
https://www.yelp.com/biz/menchies-frozen-yogur...
NaN
621162
military-dairy-queen-niagara-falls
Military Dairy Queen
Niagara Falls
New York
3.0
4
3
43.101192
-78.978317
False
False
https://www.yelp.com/biz/military-dairy-queen-...
NaN
621172
adrians-custard-and-beef-grand-island
Adrian's Custard & Beef
Niagara Falls
New York
4.5
23
1
43.026038
-78.966765
False
False
https://www.yelp.com/biz/adrians-custard-and-b...
NaN
621191
hoovers-dairy-sanborn-2
Hoover's Dairy
Niagara Falls
New York
4.0
25
1
43.131100
-78.885510
False
False
https://www.yelp.com/biz/hoovers-dairy-sanborn...
NaN
621215
tcby-niagara-falls
TCBY
Niagara Falls
New York
5.0
1
1
43.096984
-78.974058
False
False
https://www.yelp.com/biz/tcby-niagara-falls?ad...
NaN
621231
yogen-fruz-niagara-falls-2
Yogen Fruz
Niagara Falls
New York
4.0
5
3
43.097549
-78.978790
False
False
https://www.yelp.com/biz/yogen-fruz-niagara-fa...
NaN
621253
sweet-jesus-niagara-falls
Sweet Jesus
Niagara Falls
New York
4.5
8
2
43.090691
-79.073136
False
False
https://www.yelp.com/biz/sweet-jesus-niagara-f...
NaN
621314
twist-o-the-mist-niagara-falls
Twist O'the Mist
Niagara Falls
New York
3.5
26
1
43.088450
-79.062960
False
False
https://www.yelp.com/biz/twist-o-the-mist-niag...
NaN
621336
cold-stone-creamery-niagara-falls
Cold Stone Creamery
Niagara Falls
New York
1.0
3
3
43.085829
-79.057830
False
False
https://www.yelp.com/biz/cold-stone-creamery-n...
NaN
621362
hertel-avenue-poutine-and-cream-buffalo
Hertel Avenue Poutine & Cream
Niagara Falls
New York
4.0
95
1
42.948007
-78.852864
False
False
https://www.yelp.com/biz/hertel-avenue-poutine...
NaN
621383
ilgelato-di-carlotta-niagara-falls
ILGelato Di Carlotta
Niagara Falls
New York
4.5
19
2
43.081740
-79.080840
False
False
https://www.yelp.com/biz/ilgelato-di-carlotta-...
NaN
621396
italian-ice-cream-niagara-falls
Italian Ice Cream
Niagara Falls
New York
4.5
26
1
43.095540
-79.072420
False
False
https://www.yelp.com/biz/italian-ice-cream-nia...
NaN
621476
lake-effect-artisan-ice-cream-buffalo
Lake Effect Artisan Ice Cream
Niagara Falls
New York
4.5
79
1
42.947740
-78.837470
False
False
https://www.yelp.com/biz/lake-effect-artisan-i...
NaN
621521
andersons-frozen-custard-kenmore
Anderson's Frozen Custard
Niagara Falls
New York
4.5
68
1
42.980530
-78.850920
False
False
https://www.yelp.com/biz/andersons-frozen-cust...
NaN
621524
canalside-creamery-north-tonawanda
Canalside Creamery
Niagara Falls
New York
4.5
11
1
43.024100
-78.877650
False
False
https://www.yelp.com/biz/canalside-creamery-no...
NaN
621563
andersons-frozen-custard-amherst
Anderson's Frozen Custard
Niagara Falls
New York
4.0
26
1
43.019060
-78.821658
False
False
https://www.yelp.com/biz/andersons-frozen-cust...
NaN
621568
table-rock-ice-cream-niagara-falls
Table Rock Ice Cream
Niagara Falls
New York
3.0
1
3
43.079132
-79.078886
False
False
https://www.yelp.com/biz/table-rock-ice-cream-...
NaN
621598
snack-shack-niagara-falls-3
Snack Shack
Niagara Falls
New York
4.0
1
1
43.087880
-79.081420
False
False
https://www.yelp.com/biz/snack-shack-niagara-f...
NaN
621607
andersons-frozen-custard-buffalo
Anderson's Frozen Custard
Niagara Falls
New York
4.0
51
1
42.955452
-78.869872
False
False
https://www.yelp.com/biz/andersons-frozen-cust...
NaN
621620
churn-soft-serve-buffalo
Churn Soft Serve
Niagara Falls
New York
4.0
49
2
42.947510
-78.852550
False
False
https://www.yelp.com/biz/churn-soft-serve-buff...
NaN
621716
baskin-robbins-niagara-falls-2
Baskin Robbins
Niagara Falls
New York
5.0
1
3
43.090350
-79.079850
False
False
https://www.yelp.com/biz/baskin-robbins-niagar...
NaN
621795
the-flavor-factory-north-tonawanda
The Flavor Factory
Niagara Falls
New York
4.0
7
1
43.022690
-78.877420
False
False
https://www.yelp.com/biz/the-flavor-factory-no...
NaN
621810
chilly-billys-ice-cream-tonawanda-2
Chilly Billys Ice Cream
Niagara Falls
New York
5.0
2
1
42.979450
-78.897857
False
False
https://www.yelp.com/biz/chilly-billys-ice-cre...
NaN
621903
platters-chocolates-north-tonawanda
Platter's Chocolates
Niagara Falls
New York
4.5
24
2
43.061050
-78.842720
False
False
https://www.yelp.com/biz/platters-chocolates-n...
NaN
621913
watsons-chocolates-buffalo
Watson's Chocolates
Niagara Falls
New York
5.0
5
2
42.963482
-78.870394
False
False
https://www.yelp.com/biz/watsons-chocolates-bu...
NaN
621950
mister-softee-buffalo
Mister Softee
Niagara Falls
New York
2.5
2
3
42.953279
-78.893563
False
False
https://www.yelp.com/biz/mister-softee-buffalo...
NaN
13349 rows × 13 columns
In [18]:
df_rest.loc[(df_rest.loc[(df_cats['icecream']==1) &
((df_cats['hotdog']==1) |
(df_cats['hotdogs']==1))].index),
'icedog'] = 'hotdog_and_icecream'
df_rest.loc[(df_rest.loc[(df_cats['icecream']==0) &
((df_cats['hotdog']==1) |
(df_cats['hotdogs']==1))].index),
'icedog'] = 'hotdog_only'
df_rest.loc[(df_rest.loc[(df_cats['icecream']==1) &
((df_cats['hotdog']==0) &
(df_cats['hotdogs']==0))].index),
'icedog'] = 'icecream_only'
df_rest.loc[(df_rest.loc[(df_cats['icecream']==0) &
((df_cats['hotdog']==0) &
(df_cats['hotdogs']==0))].index),
'icedog'] = 'field'
In [19]:
df_rest['icedog'].value_counts()
Out[19]:
field 544910
hotdog_only 61859
icecream_only 13349
hotdog_and_icecream 1833
Name: icedog, dtype: int64
In [20]:
df_rest['icedog'] = pd.Categorical(df_rest['icedog'])
In [21]:
results = pd.DataFrame()
for x, y in itertools.product(df_rest['icedog'].cat.codes.unique(), df_rest['icedog'].cat.codes.unique()):
temp = pd.DataFrame()
temp['x'] = [x]
temp['y'] = y
a,b = stats.mannwhitneyu(df_rest.loc[df_rest['icedog'].cat.codes==x,'rating'], df_rest.loc[df_rest['icedog'].cat.codes==y,'rating'])
temp['U'] = a
temp['pval'] = b
results = results.append(temp, ignore_index=True)
results
Out[21]:
x
y
U
pval
0
0
0
1.484635e+11
5.000000e-01
1
0
3
3.305848e+09
3.078902e-76
2
0
2
9.592704e+09
0.000000e+00
3
0
1
3.375633e+08
1.048778e-133
4
3
0
3.305848e+09
3.078902e-76
5
3
3
8.909790e+07
4.999997e-01
6
3
2
2.181554e+08
0.000000e+00
7
3
1
7.555414e+06
3.332300e-162
8
2
0
9.592704e+09
0.000000e+00
9
2
3
2.181554e+08
0.000000e+00
10
2
2
1.913268e+09
5.000000e-01
11
2
1
4.838809e+07
1.467280e-27
12
1
0
3.375633e+08
1.048778e-133
13
1
3
7.555414e+06
3.332300e-162
14
1
2
4.838809e+07
1.467280e-27
15
1
1
1.679944e+06
4.999937e-01
In [22]:
df_rest['icedog'].cat.categories
Out[22]:
Index(['field', 'hotdog_and_icecream', 'hotdog_only', 'icecream_only'], dtype='object')
In [23]:
results.loc[results['pval']<0.05].sort_values('pval')
Out[23]:
x
y
U
pval
2
0
2
9.592704e+09
0.000000e+00
6
3
2
2.181554e+08
0.000000e+00
8
2
0
9.592704e+09
0.000000e+00
9
2
3
2.181554e+08
0.000000e+00
7
3
1
7.555414e+06
3.332300e-162
13
1
3
7.555414e+06
3.332300e-162
3
0
1
3.375633e+08
1.048778e-133
12
1
0
3.375633e+08
1.048778e-133
1
0
3
3.305848e+09
3.078902e-76
4
3
0
3.305848e+09
3.078902e-76
11
2
1
4.838809e+07
1.467280e-27
14
1
2
4.838809e+07
1.467280e-27
In [24]:
df_rest['icedog'].cat.categories
Out[24]:
Index(['field', 'hotdog_and_icecream', 'hotdog_only', 'icecream_only'], dtype='object')
In [25]:
df_hist = pd.DataFrame()
df_hist['hotdog_and_icecream'] = (df_rest.loc[(df_cats['icecream']==1) &
((df_cats['hotdogs']==1) |
(df_cats['hotdogs']==1)), 'rating']
.value_counts()
.sort_index())
df_hist['hotdog_only'] = (df_rest.loc[(df_cats['icecream']==0) &
((df_cats['hotdogs']==1) |
(df_cats['hotdogs']==1)), 'rating']
.value_counts()
.sort_index())
df_hist['icecream_only'] = (df_rest.loc[(df_cats['icecream']==1) &
((df_cats['hotdogs']==0) &
(df_cats['hotdogs']==0)), 'rating']
.value_counts()
.sort_index())
df_hist['field'] = (df_rest.loc[(df_cats['icecream']==0) &
((df_cats['hotdogs']==0) &
(df_cats['hotdogs']==0)), 'rating']
.value_counts()
.sort_index())
df_hist
Out[25]:
hotdog_and_icecream
hotdog_only
icecream_only
field
1.0
57
3059
248
7903
1.5
47
3816
137
4092
2.0
127
7145
385
12318
2.5
204
8728
681
25371
3.0
267
9907
1201
57998
3.5
285
9196
1947
104538
4.0
269
9293
3618
171009
4.5
91
3788
3638
110143
5.0
39
1983
1941
56468
In [26]:
for col in df_hist.columns:
df_hist[col] = df_hist[col]/df_hist[col].sum()
In [27]:
df_hist['rating'] = df_hist.index
In [28]:
df_hist = pd.melt(df_hist, id_vars='rating')
In [29]:
sns.barplot(y='value', x='rating', data=df_hist, hue='variable')
plt.xticks(rotation=90)
plt.show()
In [30]:
df_cities['total_food'].describe()
Out[30]:
count 761.000000
mean 2834.293035
std 4182.121709
min 87.000000
25% 632.000000
50% 1389.000000
75% 3696.000000
max 54191.000000
Name: total_food, dtype: float64
In [31]:
df_rest.shape
Out[31]:
(621951, 13)
In [32]:
df_chipotle = df_rest.loc[df_rest['name'].str.lower().str.contains('chipotle')]
In [33]:
df_chipotle['idx'] = df_chipotle.index.values
df_chipotle
C:\Users\hello\Anaconda3\lib\site-packages\ipykernel_launcher.py:1: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
"""Entry point for launching an IPython kernel.
Out[33]:
id
name
city
state
rating
review_count
cost
latitude
longitude
has_delivery
has_pickup
url
icedog
idx
1341
chipotle-mexican-grill-los-angeles-55
Chipotle Mexican Grill
Los Angeles
California
3.5
11
1
34.041418
-118.258382
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
1341
3638
chipotle-mexican-grill-houston-35
Chipotle Mexican Grill
Houston
Texas
4.0
68
1
29.747211
-95.410361
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
3638
3731
chipotle-mexican-grill-houston-17
Chipotle Mexican Grill
Houston
Texas
3.5
73
1
29.709650
-95.401235
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
3731
4426
chipotle-mexican-grill-phoenix-10
Chipotle Mexican Grill
Phoenix
Arizona
3.5
63
1
33.447948
-112.074617
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
4426
4656
chipotle-mexican-grill-phoenix-25
Chipotle Mexican Grill
Phoenix
Arizona
4.5
15
1
33.509435
-112.072213
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
4656
4952
chipotle-mexican-grill-phoenix-9
Chipotle Mexican Grill
Phoenix
Arizona
3.0
123
1
33.509365
-112.046390
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
4952
6441
chipotle-mexican-grill-san-antonio-12
Chipotle Mexican Grill
San Antonio
Texas
3.5
40
1
29.519733
-98.500963
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
6441
6499
chipotle-mexican-grill-san-antonio-4
Chipotle Mexican Grill
San Antonio
Texas
4.0
41
1
29.498071
-98.480085
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
6499
6500
chipotle-mexican-grill-san-antonio-4
Chipotle Mexican Grill
San Antonio
Texas
4.0
41
1
29.498071
-98.480085
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
6500
8544
chipotle-mexican-grill-dallas-5
Chipotle Mexican Grill
Dallas
Texas
4.0
64
1
32.857560
-96.769520
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
8544
8607
chipotle-mexican-grill-dallas
Chipotle Mexican Grill
Dallas
Texas
3.5
60
1
32.780506
-96.806152
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
8607
9793
chipotle-mexican-grill-san-jose-4
Chipotle Mexican Grill
San Jose
California
3.0
289
1
37.331980
-121.908830
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
9793
9960
chipotle-mexican-grill-san-jose-3
Chipotle Mexican Grill
San Jose
California
3.0
278
1
37.370550
-121.916910
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
9960
11641
chipotle-mexican-grill-jacksonville-2
Chipotle Mexican Grill
Jacksonville
Florida
4.0
60
1
30.173410
-81.627900
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
11641
13624
chipotle-mexican-grill-columbus-20
Chipotle Mexican Grill
Columbus
Ohio
3.5
28
1
40.021025
-83.058211
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
13624
13725
chipotle-mexican-grill-columbus-7
Chipotle Mexican Grill
Columbus
Ohio
3.5
18
1
39.969704
-83.004545
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
13725
13852
chipotle-mexican-grill-columbus-22
Chipotle Mexican Grill
Columbus
Ohio
3.5
38
1
40.053950
-83.020240
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
13852
14415
chipotle-mexican-grill-indianapolis-7
Chipotle Mexican Grill
Indianapolis
Indiana
3.5
34
1
39.767109
-86.157792
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
14415
14492
chipotle-mexican-grill-indianapolis-14
Chipotle Mexican Grill
Indianapolis
Indiana
4.5
7
1
39.781855
-86.169643
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
14492
15407
chipotle-mexican-grill-fort-worth-9
Chipotle Mexican Grill
Fort Worth
Texas
3.5
8
1
32.732813
-97.343134
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
15407
15627
chipotle-mexican-grill-fort-worth
Chipotle Mexican Grill
Fort Worth
Texas
3.0
43
1
32.751700
-97.360620
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
15627
15835
chipotle-mexican-grill-fort-worth-6
Chipotle Mexican Grill
Fort Worth
Texas
3.5
18
1
32.726421
-97.422166
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
15835
16270
chipotle-mexican-grill-charlotte-13
Chipotle Mexican Grill
Charlotte
North Carolina
3.5
18
1
35.349049
-80.857670
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
16270
16385
chipotle-mexican-grill-charlotte-8
Chipotle Mexican Grill
Charlotte
North Carolina
3.0
53
1
35.213570
-80.833497
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
16385
16618
chipotle-mexican-grill-charlotte-6
Chipotle Mexican Grill
Charlotte
North Carolina
3.5
52
1
35.171265
-80.807472
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
16618
16677
chipotle-mexican-grill-charlotte-12
Chipotle Mexican Grill
Charlotte
North Carolina
3.5
91
1
35.207330
-80.860250
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
16677
16995
chipotle-mexican-grill-charlotte-14
Chipotle Mexican Grill
Charlotte
North Carolina
4.0
4
2
35.050796
-80.767278
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
field
16995
18746
chipotle-mexican-grill-denver-4
Chipotle Mexican Grill
Denver
Colorado
4.0
19
1
39.718899
-104.949463
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
18746
19226
chipotle-mexican-grill-el-paso
Chipotle Mexican Grill
El Paso
Texas
3.5
46
1
31.779076
-106.504227
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
19226
19274
chipotle-mexican-grill-fort-bliss
Chipotle Mexican Grill
El Paso
Texas
4.0
6
1
31.817125
-106.427530
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
19274
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
612410
chipotle-mexican-grill-olympia
Chipotle Mexican Grill
Olympia
Washington
3.5
67
1
47.041394
-122.934536
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
612410
612842
chipotle-mexican-grill-lacey-2
Chipotle Mexican Grill
Olympia
Washington
3.5
21
1
47.057420
-122.764727
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
612842
613093
chipotle-mexican-grill-parker-2
Chipotle Mexican Grill
Parker
Colorado
3.0
33
1
39.557278
-104.778297
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
613093
613154
chipotle-mexican-grill-parker
Chipotle Mexican Grill
Parker
Colorado
2.5
44
1
39.518719
-104.770418
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
613154
613358
chipotle-mexican-grill-centennial-4
Chipotle Mexican Grill
Parker
Colorado
3.5
31
1
39.595562
-104.848763
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
613358
613410
chipotle-mexican-grill-aurora-7
Chipotle Mexican Grill
Parker
Colorado
3.5
28
1
39.604513
-104.707013
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
613410
613430
chipotle-mexican-grill-aurora-15
Chipotle Mexican Grill
Parker
Colorado
2.5
8
1
39.594550
-104.806306
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
613430
614539
chipotle-mexican-grill-miami-15
Chipotle Mexican Grill
Coral Gables
Florida
4.5
7
2
25.809235
-80.314892
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
614539
614564
chipotle-mexican-grill-miami-7
Chipotle Mexican Grill
Coral Gables
Florida
3.5
179
1
25.699500
-80.295010
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
614564
614715
chipotle-mexican-grill-miami-9
Chipotle Mexican Grill
Coral Gables
Florida
2.5
126
1
25.749348
-80.254465
True
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
614715
615418
chipotle-mexican-grill-watchung
Chipotle Mexican Grill
Plainfield
New Jersey
4.0
4
3
40.642970
-74.411520
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
615418
615426
chipotle-mexican-grill-watchung-2
Chipotle Mexican Grill
Plainfield
New Jersey
2.5
2
1
40.642970
-74.411520
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
615426
615707
chipotle-mexican-grill-cerritos-2
Chipotle Mexican Grill
Cerritos
California
3.0
295
1
33.872800
-118.064260
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
615707
615926
chipotle-mexican-grill-cerritos-4
Chipotle Mexican Grill
Cerritos
California
2.0
35
1
33.860328
-118.092221
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
615926
617098
chipotle-mexican-grill-coeur-d-alene-2
Chipotle Mexican Grill
Coeur d'Alene
Idaho
2.5
18
1
47.701038
-116.789903
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
617098
617505
chipotle-mexican-grill-lakewood-3
Chipotle Mexican Grill
Lakewood
Ohio
2.5
47
1
41.484820
-81.801030
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
617505
617747
chipotle-mexican-grill-cleveland-11
Chipotle Mexican Grill
Lakewood
Ohio
2.5
35
1
41.450260
-81.814056
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
617747
617798
chipotle-mexican-grill-fairview-park
Chipotle Mexican Grill
Lakewood
Ohio
3.0
27
1
41.461254
-81.853058
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
617798
618108
chipotle-mexican-grill-brooklyn-4
Chipotle Mexican Grill
Lakewood
Ohio
2.5
42
1
41.423140
-81.759430
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
618108
618368
chipotle-mexican-grill-poway
Chipotle Mexican Grill
Poway
California
3.5
95
1
32.957837
-117.039868
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
618368
618704
chipotle-mexican-grill-san-diego-6
Chipotle Mexican Grill
Poway
California
2.5
129
1
32.979670
-117.082590
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
618704
618720
chipotle-mexican-grill-san-diego-9
Chipotle Mexican Grill
Poway
California
3.5
66
1
33.020027
-117.111085
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
618720
619684
chipotle-mexican-grill-latham-2
Chipotle Mexican Grill
Troy
New York
3.5
45
1
42.755728
-73.776027
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
619684
619711
chipotle-mexican-grill-albany-2
Chipotle Mexican Grill
Troy
New York
4.0
42
1
42.715800
-73.809580
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
619711
619963
chipotle-mexican-grill-albany
Chipotle Mexican Grill
Troy
New York
3.5
77
1
42.683173
-73.838482
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
619963
620027
chipotle-mexican-grill-clifton-park
Chipotle Mexican Grill
Troy
New York
3.5
21
1
42.859410
-73.778560
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
620027
620223
chipotle-mexican-grill-charleston-3
Chipotle Mexican Grill
Charleston
West Virginia
4.0
8
1
38.318560
-81.718721
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
620223
620615
chipotle-mexican-grill-saginaw
Chipotle Mexican Grill
Saginaw
Michigan
3.5
18
1
43.479994
-83.970399
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
620615
621057
chipotle-mexican-grill-niagara-falls-3
Chipotle Mexican Grill
Niagara Falls
New York
3.0
25
1
43.096880
-78.973870
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
621057
621614
chipotle-mexican-grill-amherst
Chipotle Mexican Grill
Niagara Falls
New York
3.5
74
1
42.999785
-78.819510
False
False
https://www.yelp.com/biz/chipotle-mexican-gril...
hotdog_only
621614
1942 rows × 14 columns
In [34]:
(df_chipotle
.loc[df_chipotle['state']
.isin(['California', 'Florida',
'Texas', 'Illinois']), 'rating']).hist(bins=6)
Out[34]:
<matplotlib.axes._subplots.AxesSubplot at 0x24c8019e588>
In [35]:
df_plt = df_chipotle.loc[df_chipotle['state']
.isin(['California', 'Florida',
'Texas', 'Illinois'])]
g = sns.FacetGrid(df_plt, col='state', col_wrap=2, size=4)
g.map(sns.distplot, 'rating', kde=True, bins=5)
plt.show()
In [36]:
df_plt[['idx', 'state', 'rating']].to_csv('df_chipotle.csv')
In [37]:
df_plt.loc[df_plt['has_delivery']==True].shape[0]/df_plt.shape[0]
Out[37]:
0.030508474576271188
In [98]:
shitty_food = ["Burger King", 'Cracker Barrel Old Country Store', "Wendy's",
'IHOP', "Zaxby's Chicken Fingers & Buffalo Wings",
'Chipotle Mexican Grill', 'Taco Bell', "Sonny's BBQ",
"Buffalo Wild Wings", "Hooters"]
df_rest.loc[(df_rest['state']
.isin(['California', 'Florida',
'Texas', 'Illinois'])) &
(df_rest['name'].isin(shitty_food))].to_csv('shitty_food.csv')
In [104]:
data = df_rest.loc[df_rest['name'] == 'Taco Bell']
In [105]:
df_plt = data.groupby(['city', 'state'], as_index=False).mean()
df_plt['citystate'] = df_plt['city'].str.lower() + ', ' + df_plt['state'].str.lower()
In [106]:
palette = sns.color_palette("Blues", 10)
sns.palplot(palette)
sns.despine(bottom=True, left=True)
plt.show()
In [107]:
latcorners = df_plt['latitude']
loncorners = df_plt['longitude']
fig = plt.figure(figsize=(10,10))
ax = fig.add_axes([0.1,0.1,0.8,0.8])
m = Basemap(projection='stere',lon_0=-100,lat_0=40,lat_ts=40,
llcrnrlat=20,urcrnrlat=51,
llcrnrlon=-120,urcrnrlon=-60,
rsphere=6371200.,resolution='l',area_thresh=10000)
m.drawcoastlines()
m.drawstates()
m.drawcountries()
f = m.scatter(df_plt['longitude'].values, df_plt['latitude'].values, 40,
marker='o',c=df_plt['rating'].values, cmap='coolwarm', latlon=True)
cbar = m.colorbar(f,location='bottom',pad="5%")
cbar.set_label('rating')
sns.despine(left=True, bottom=True)
plt.show()
C:\Users\hello\Anaconda3\lib\site-packages\mpl_toolkits\basemap\__init__.py:3236: MatplotlibDeprecationWarning: The ishold function was deprecated in version 2.0.
b = ax.ishold()
C:\Users\hello\Anaconda3\lib\site-packages\mpl_toolkits\basemap\__init__.py:3245: MatplotlibDeprecationWarning: axes.hold is deprecated.
See the API Changes document (http://matplotlib.org/api/api_changes.html)
for more details.
ax.hold(b)
In [128]:
df_cats.sum().sort_values(ascending=False)
Out[128]:
sandwiches 64723
mexican 62550
hotdogs 58303
tradamerican 52656
pizza 50188
burgers 48277
breakfast_brunch 39025
newamerican 31026
coffee 29987
italian 28380
seafood 26280
chinese 26267
grocery 22727
salad 22291
bakeries 20171
bars 19994
foodtrucks 19650
chicken_wings 17667
japanese 16973
delis 16854
sushi 16021
catering 15751
desserts 15228
icecream 15182
bbq 15170
convenience 14308
cafes 14229
asianfusion 12304
mediterranean 11744
sportsbars 11618
...
mailboxcenters 1
vacation_rentals 1
musicproduction 1
petbreeders 1
homeappliancerepair 1
hearingaidproviders 1
challengecourses 1
personalassistants 1
bespoke 1
holidaydecorations 1
partycharacters 1
partybusrentals 1
university_housing 1
birdshops 1
blowoutservices 1
paintball 1
painmanagement 1
northernmexican 1
boatrepair 1
unofficialyelpevents 1
homeservices 1
hostels 1
tableware 1
sommelierservices 1
boxing 1
computers 1
opera 1
communitygardens 1
officiants 1
skishops 1
Length: 684, dtype: int64
In [129]:
df_rest.loc[df_cats['hotdogs']==1, 'is_hotdogs'] = 1
df_rest['is_hotdogs'] = df_rest['is_hotdogs'].fillna(0)
In [130]:
data = df_rest.groupby(['city', 'state'], as_index=False).mean()
df_plt = data.groupby(['city', 'state'], as_index=False).mean()
df_plt['citystate'] = df_plt['city'].str.lower() + ', ' + df_plt['state'].str.lower()
In [131]:
palette = sns.color_palette("Blues", 10)
sns.palplot(palette)
sns.despine(bottom=True, left=True)
plt.show()
In [133]:
latcorners = df_plt['latitude']
loncorners = df_plt['longitude']
fig = plt.figure(figsize=(10,10))
ax = fig.add_axes([0.1,0.1,0.8,0.8])
m = Basemap(projection='stere',lon_0=-100,lat_0=40,lat_ts=40,
llcrnrlat=20,urcrnrlat=51,
llcrnrlon=-120,urcrnrlon=-60,
rsphere=6371200.,resolution='l',area_thresh=10000)
m.drawcoastlines()
m.drawstates()
m.drawcountries()
f = m.scatter(df_plt['longitude'].values, df_plt['latitude'].values, 40,
marker='o',c=df_plt['is_hotdogs'].values, cmap='coolwarm', latlon=True)
cbar = m.colorbar(f,location='bottom',pad="5%")
# cbar.set_label('rating')
sns.despine(left=True, bottom=True)
plt.show()
C:\Users\hello\Anaconda3\lib\site-packages\mpl_toolkits\basemap\__init__.py:3236: MatplotlibDeprecationWarning: The ishold function was deprecated in version 2.0.
b = ax.ishold()
C:\Users\hello\Anaconda3\lib\site-packages\mpl_toolkits\basemap\__init__.py:3245: MatplotlibDeprecationWarning: axes.hold is deprecated.
See the API Changes document (http://matplotlib.org/api/api_changes.html)
for more details.
ax.hold(b)
In [138]:
df_plt = df_plt.merge(df_cities[['city', 'state', 'population']], on=['city', 'state'])
In [160]:
spearmanr(df_plt['population'], df_plt['is_mex'])
Out[160]:
SpearmanrResult(correlation=0.15158203120957076, pvalue=2.681090091023933e-05)
In [159]:
spearmanr(np.log(df_plt['population']), df_plt['is_mex'])
Out[159]:
SpearmanrResult(correlation=0.15158203120957076, pvalue=2.681090091023933e-05)
In [161]:
spearmanr(df_plt['population'], df_plt['is_hotdogs'])
Out[161]:
SpearmanrResult(correlation=-0.15038384078632075, pvalue=3.1078814021019139e-05)
In [157]:
plt.plot(df_plt['population'], df_plt['is_mex'], 'k.')
ax = plt.gca()
ax.set_xscale('log')
In [155]:
g = sns.regplot('population', 'is_mex', df_plt)
ax = plt.gca()
ax.set_xscale('log')
plt.show()
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
~\Anaconda3\lib\site-packages\IPython\core\formatters.py in __call__(self, obj)
330 pass
331 else:
--> 332 return printer(obj)
333 # Finally look for special method names
334 method = get_real_method(obj, self.print_method)
~\Anaconda3\lib\site-packages\IPython\core\pylabtools.py in <lambda>(fig)
235
236 if 'png' in formats:
--> 237 png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
238 if 'retina' in formats or 'png2x' in formats:
239 png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))
~\Anaconda3\lib\site-packages\IPython\core\pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs)
119
120 bytes_io = BytesIO()
--> 121 fig.canvas.print_figure(bytes_io, **kw)
122 data = bytes_io.getvalue()
123 if fmt == 'svg':
~\Anaconda3\lib\site-packages\matplotlib\backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
2206 orientation=orientation,
2207 dryrun=True,
-> 2208 **kwargs)
2209 renderer = self.figure._cachedRenderer
2210 bbox_inches = self.figure.get_tightbbox(renderer)
~\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py in print_png(self, filename_or_obj, *args, **kwargs)
505
506 def print_png(self, filename_or_obj, *args, **kwargs):
--> 507 FigureCanvasAgg.draw(self)
508 renderer = self.get_renderer()
509 original_dpi = renderer.dpi
~\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py in draw(self)
428 if toolbar:
429 toolbar.set_cursor(cursors.WAIT)
--> 430 self.figure.draw(self.renderer)
431 finally:
432 if toolbar:
~\Anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
53 renderer.start_filter()
54
---> 55 return draw(artist, renderer, *args, **kwargs)
56 finally:
57 if artist.get_agg_filter() is not None:
~\Anaconda3\lib\site-packages\matplotlib\figure.py in draw(self, renderer)
1293
1294 mimage._draw_list_compositing_images(
-> 1295 renderer, self, artists, self.suppressComposite)
1296
1297 renderer.close_group('figure')
~\Anaconda3\lib\site-packages\matplotlib\image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
136 if not_composite or not has_images:
137 for a in artists:
--> 138 a.draw(renderer)
139 else:
140 # Composite any adjacent images together
~\Anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
53 renderer.start_filter()
54
---> 55 return draw(artist, renderer, *args, **kwargs)
56 finally:
57 if artist.get_agg_filter() is not None:
~\Anaconda3\lib\site-packages\matplotlib\axes\_base.py in draw(self, renderer, inframe)
2397 renderer.stop_rasterizing()
2398
-> 2399 mimage._draw_list_compositing_images(renderer, self, artists)
2400
2401 renderer.close_group('axes')
~\Anaconda3\lib\site-packages\matplotlib\image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
136 if not_composite or not has_images:
137 for a in artists:
--> 138 a.draw(renderer)
139 else:
140 # Composite any adjacent images together
~\Anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
53 renderer.start_filter()
54
---> 55 return draw(artist, renderer, *args, **kwargs)
56 finally:
57 if artist.get_agg_filter() is not None:
~\Anaconda3\lib\site-packages\matplotlib\axis.py in draw(self, renderer, *args, **kwargs)
1145 self._update_label_position(ticklabelBoxes, ticklabelBoxes2)
1146
-> 1147 self.label.draw(renderer)
1148
1149 self._update_offset_text_position(ticklabelBoxes, ticklabelBoxes2)
~\Anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
53 renderer.start_filter()
54
---> 55 return draw(artist, renderer, *args, **kwargs)
56 finally:
57 if artist.get_agg_filter() is not None:
~\Anaconda3\lib\site-packages\matplotlib\text.py in draw(self, renderer)
761 posy = float(textobj.convert_yunits(textobj._y))
762 if not np.isfinite(posx) or not np.isfinite(posy):
--> 763 raise ValueError("posx and posy should be finite values")
764 posx, posy = trans.transform_point((posx, posy))
765 canvasw, canvash = renderer.get_canvas_width_height()
ValueError: posx and posy should be finite values
<matplotlib.figure.Figure at 0x24c8a5e2390>
In [ ]:
# data from http://water.weather.gov/precip/
# create figure and axes instances
# create polar stereographic Basemap instance.
# draw coastlines, state and country boundaries, edge of map.
# draw parallels.
parallels = np.arange(0.,90,10.)
m.drawparallels(parallels,labels=[1,0,0,0],fontsize=10)
# draw meridians
meridians = np.arange(180.,360.,10.)
m.drawmeridians(meridians,labels=[0,0,0,1],fontsize=10)
ny = data.shape[0]; nx = data.shape[1]
lons, lats = m.makegrid(nx, ny) # get lat/lons of ny by nx evenly space grid.
x, y = m(lons, lats) # compute map proj coordinates.
# draw filled contours.
clevs = [0,1,2.5,5,7.5,10,15,20,30,40,50,70,100,150,200,250,300,400,500,600,750]
cs = m.contourf(x,y,data,clevs,cmap=cm.s3pcpn)
# add colorbar.
cbar = m.colorbar(cs,location='bottom',pad="5%")
cbar.set_label('mm')
# add title
plt.title(prcpvar.long_name+' for period ending '+prcpvar.dateofdata)
plt.show()
Content source: srcole/qwm
Similar notebooks: