Encoding


In [66]:
%matplotlib inline

import os
import pandas as pd
import matplotlib.pyplot as plt

In [84]:
data = '/Users/skhederian/restaurant-health/the_final_countdown.csv'

names = [
    "_id",
    "restaurant_name",
    "address_full",
    "business_id",
    "categories",
    "city",
    "review_count",
    "inspection_date",
    "stars",
    "latitude",
    "longitude",
    "attributes",
    "open",
    "neighborhoods",
    "violations"
  ]

    
df = pd.read_csv(data)
df.head(1000)


Out[84]:
Unnamed: 0 _id restaurant_name address_full business_id categories city review_count inspection_date stars ... creditcards pricerange drivethru tourist classy hipster latenight upscale divey Neighborhoods
0 0 ObjectId(581151a3b6729e7e313418da) TLC WINGS & GRILL 9101 PINEVILLE-MATTHEWS RD lX3XYcMWoRlHjrmkoGNefQ ["Chicken Wings","Restaurants"] 2 29 1/10/2012 4.0 ... 1 1 0 0 0 0 0 0 0 none
1 1 ObjectId(581151a3b6729e7e313418da) TLC WINGS & GRILL 9101 PINEVILLE-MATTHEWS RD lX3XYcMWoRlHjrmkoGNefQ ["Chicken Wings","Restaurants"] 2 29 4/20/2012 4.0 ... 1 1 0 0 0 0 0 0 0 none
2 2 ObjectId(581151a3b6729e7e313418da) TLC WINGS & GRILL 9101 PINEVILLE-MATTHEWS RD lX3XYcMWoRlHjrmkoGNefQ ["Chicken Wings","Restaurants"] 2 29 8/3/2012 4.0 ... 1 1 0 0 0 0 0 0 0 none
3 3 ObjectId(581151a3b6729e7e313418da) TLC WINGS & GRILL 9101 PINEVILLE-MATTHEWS RD lX3XYcMWoRlHjrmkoGNefQ ["Chicken Wings","Restaurants"] 2 29 1/24/2013 4.0 ... 1 1 0 0 0 0 0 0 0 none
4 4 ObjectId(581151a3b6729e7e313418da) TLC WINGS & GRILL 9101 PINEVILLE-MATTHEWS RD lX3XYcMWoRlHjrmkoGNefQ ["Chicken Wings","Restaurants"] 2 29 4/22/2013 4.0 ... 1 1 0 0 0 0 0 0 0 none
5 5 ObjectId(581151a3b6729e7e313418da) TLC WINGS & GRILL 9101 PINEVILLE-MATTHEWS RD lX3XYcMWoRlHjrmkoGNefQ ["Chicken Wings","Restaurants"] 2 29 10/4/2013 4.0 ... 1 1 0 0 0 0 0 0 0 none
6 6 ObjectId(581151a3b6729e7e313418da) TLC WINGS & GRILL 9101 PINEVILLE-MATTHEWS RD lX3XYcMWoRlHjrmkoGNefQ ["Chicken Wings","Restaurants"] 2 29 4/3/2014 4.0 ... 1 1 0 0 0 0 0 0 0 none
7 7 ObjectId(581151a3b6729e7e313418da) TLC WINGS & GRILL 9101 PINEVILLE-MATTHEWS RD lX3XYcMWoRlHjrmkoGNefQ ["Chicken Wings","Restaurants"] 2 29 1/9/2015 4.0 ... 1 1 0 0 0 0 0 0 0 none
8 8 ObjectId(581151a3b6729e7e313418da) TLC WINGS & GRILL 9101 PINEVILLE-MATTHEWS RD lX3XYcMWoRlHjrmkoGNefQ ["Chicken Wings","Restaurants"] 2 29 7/1/2015 4.0 ... 1 1 0 0 0 0 0 0 0 none
9 9 ObjectId(581151a3b6729e7e313418da) TLC WINGS & GRILL 9101 PINEVILLE-MATTHEWS RD lX3XYcMWoRlHjrmkoGNefQ ["Chicken Wings","Restaurants"] 2 29 2/3/2016 4.0 ... 1 1 0 0 0 0 0 0 0 none
10 10 ObjectId(581151a3b6729e7e313418da) TLC WINGS & GRILL 9101 PINEVILLE-MATTHEWS RD lX3XYcMWoRlHjrmkoGNefQ ["Chicken Wings","Restaurants"] 2 29 8/15/2016 4.0 ... 1 1 0 0 0 0 0 0 0 none
11 11 ObjectId(581151a3b6729e7e313418e2) COMFORT SUITES 10415 CENTRUM PARKWAY ljk9LMGlc8ItupjrSKBoRg ["Hotels \u0026 Travel","Event Planning \u0026... 2 10 4/17/2012 4.0 ... 1 2 0 0 0 0 0 0 0 none
12 12 ObjectId(581151a3b6729e7e313418e2) COMFORT SUITES 10415 CENTRUM PARKWAY ljk9LMGlc8ItupjrSKBoRg ["Hotels \u0026 Travel","Event Planning \u0026... 2 10 12/27/2012 4.0 ... 1 2 0 0 0 0 0 0 0 none
13 13 ObjectId(581151a3b6729e7e313418f6) WALDHORN RESTAURANT 12101 LANCASTER HIGHWAY 2_0P2AmSSFtPgddio0MgYA ["German","Restaurants"] 2 175 3/16/2012 5.0 ... 1 2 0 0 0 0 0 0 0 none
14 14 ObjectId(581151a3b6729e7e313418f6) WALDHORN RESTAURANT 12101 LANCASTER HIGHWAY 2_0P2AmSSFtPgddio0MgYA ["German","Restaurants"] 2 175 6/21/2012 5.0 ... 1 2 0 0 0 0 0 0 0 none
15 15 ObjectId(581151a3b6729e7e313418f6) WALDHORN RESTAURANT 12101 LANCASTER HIGHWAY 2_0P2AmSSFtPgddio0MgYA ["German","Restaurants"] 2 175 11/2/2012 5.0 ... 1 2 0 0 0 0 0 0 0 none
16 16 ObjectId(581151a3b6729e7e313418f6) WALDHORN RESTAURANT 12101 LANCASTER HIGHWAY 2_0P2AmSSFtPgddio0MgYA ["German","Restaurants"] 2 175 3/20/2013 5.0 ... 1 2 0 0 0 0 0 0 0 none
17 17 ObjectId(581151a3b6729e7e313418f6) WALDHORN RESTAURANT 12101 LANCASTER HIGHWAY 2_0P2AmSSFtPgddio0MgYA ["German","Restaurants"] 2 175 8/8/2013 5.0 ... 1 2 0 0 0 0 0 0 0 none
18 18 ObjectId(581151a3b6729e7e313418f6) WALDHORN RESTAURANT 12101 LANCASTER HIGHWAY 2_0P2AmSSFtPgddio0MgYA ["German","Restaurants"] 2 175 4/2/2014 5.0 ... 1 2 0 0 0 0 0 0 0 none
19 19 ObjectId(581151a3b6729e7e313418f6) WALDHORN RESTAURANT 12101 LANCASTER HIGHWAY 2_0P2AmSSFtPgddio0MgYA ["German","Restaurants"] 2 175 9/19/2014 5.0 ... 1 2 0 0 0 0 0 0 0 none
20 20 ObjectId(581151a3b6729e7e313418f6) WALDHORN RESTAURANT 12101 LANCASTER HIGHWAY 2_0P2AmSSFtPgddio0MgYA ["German","Restaurants"] 2 175 3/12/2015 5.0 ... 1 2 0 0 0 0 0 0 0 none
21 21 ObjectId(581151a3b6729e7e313418f6) WALDHORN RESTAURANT 12101 LANCASTER HIGHWAY 2_0P2AmSSFtPgddio0MgYA ["German","Restaurants"] 2 175 7/29/2015 5.0 ... 1 2 0 0 0 0 0 0 0 none
22 22 ObjectId(581151a3b6729e7e313418f6) WALDHORN RESTAURANT 12101 LANCASTER HIGHWAY 2_0P2AmSSFtPgddio0MgYA ["German","Restaurants"] 2 175 12/11/2015 5.0 ... 1 2 0 0 0 0 0 0 0 none
23 23 ObjectId(581151a3b6729e7e313418f6) WALDHORN RESTAURANT 12101 LANCASTER HIGHWAY 2_0P2AmSSFtPgddio0MgYA ["German","Restaurants"] 2 175 3/30/2016 5.0 ... 1 2 0 0 0 0 0 0 0 none
24 24 ObjectId(581151a3b6729e7e313418f6) WALDHORN RESTAURANT 12101 LANCASTER HIGHWAY 2_0P2AmSSFtPgddio0MgYA ["German","Restaurants"] 2 175 6/30/2016 5.0 ... 1 2 0 0 0 0 0 0 0 none
25 25 ObjectId(581151a3b6729e7e313418f6) WALDHORN RESTAURANT 12101 LANCASTER HIGHWAY 2_0P2AmSSFtPgddio0MgYA ["German","Restaurants"] 2 175 9/28/2016 5.0 ... 1 2 0 0 0 0 0 0 0 none
26 26 ObjectId(581151a3b6729e7e3134191d) CHINA BUFFET 9931 LEE ST 5p3Tqyp19UowO0-dAFvxMw ["Buffets","Chinese","Restaurants"] 2 38 3/29/2012 3.0 ... 1 2 0 0 0 0 0 0 0 none
27 27 ObjectId(581151a3b6729e7e3134191d) CHINA BUFFET 9931 LEE ST 5p3Tqyp19UowO0-dAFvxMw ["Buffets","Chinese","Restaurants"] 2 38 6/27/2012 3.0 ... 1 2 0 0 0 0 0 0 0 none
28 28 ObjectId(581151a3b6729e7e3134191d) CHINA BUFFET 9931 LEE ST 5p3Tqyp19UowO0-dAFvxMw ["Buffets","Chinese","Restaurants"] 2 38 10/26/2012 3.0 ... 1 2 0 0 0 0 0 0 0 none
29 29 ObjectId(581151a3b6729e7e3134191d) CHINA BUFFET 9931 LEE ST 5p3Tqyp19UowO0-dAFvxMw ["Buffets","Chinese","Restaurants"] 2 38 3/28/2013 3.0 ... 1 2 0 0 0 0 0 0 0 none
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
970 970 ObjectId(581151a4b6729e7e31343725) See's Candies 1300 W Sunset Rd Henderson 89014-6620 7ei7R9Cen4x4S_fs2lxf7w ["Shopping","Food","Candy Stores","Chocolatier... 3 13 6/30/2011 5.0 ... 1 2 0 0 0 0 0 0 0 none
971 971 ObjectId(581151a4b6729e7e31343725) See's Candies 1300 W Sunset Rd Henderson 89014-6620 7ei7R9Cen4x4S_fs2lxf7w ["Shopping","Food","Candy Stores","Chocolatier... 3 13 5/3/2012 5.0 ... 1 2 0 0 0 0 0 0 0 none
972 972 ObjectId(581151a4b6729e7e31343725) See's Candies 1300 W Sunset Rd Henderson 89014-6620 7ei7R9Cen4x4S_fs2lxf7w ["Shopping","Food","Candy Stores","Chocolatier... 3 13 5/3/2012 5.0 ... 1 2 0 0 0 0 0 0 0 none
973 973 ObjectId(581151a4b6729e7e31343725) See's Candies 1300 W Sunset Rd Henderson 89014-6620 7ei7R9Cen4x4S_fs2lxf7w ["Shopping","Food","Candy Stores","Chocolatier... 3 13 5/14/2013 5.0 ... 1 2 0 0 0 0 0 0 0 none
974 974 ObjectId(581151a4b6729e7e31343725) See's Candies 1300 W Sunset Rd Henderson 89014-6620 7ei7R9Cen4x4S_fs2lxf7w ["Shopping","Food","Candy Stores","Chocolatier... 3 13 5/14/2013 5.0 ... 1 2 0 0 0 0 0 0 0 none
975 975 ObjectId(581151a4b6729e7e31343725) See's Candies 1300 W Sunset Rd Henderson 89014-6620 7ei7R9Cen4x4S_fs2lxf7w ["Shopping","Food","Candy Stores","Chocolatier... 3 13 4/7/2014 5.0 ... 1 2 0 0 0 0 0 0 0 none
976 976 ObjectId(581151a4b6729e7e31343725) See's Candies 1300 W Sunset Rd Henderson 89014-6620 7ei7R9Cen4x4S_fs2lxf7w ["Shopping","Food","Candy Stores","Chocolatier... 3 13 4/7/2014 5.0 ... 1 2 0 0 0 0 0 0 0 none
977 977 ObjectId(581151a4b6729e7e31343725) See's Candies 1300 W Sunset Rd Henderson 89014-6620 7ei7R9Cen4x4S_fs2lxf7w ["Shopping","Food","Candy Stores","Chocolatier... 3 13 1/2/2015 5.0 ... 1 2 0 0 0 0 0 0 0 none
978 978 ObjectId(581151a4b6729e7e31343725) See's Candies 1300 W Sunset Rd Henderson 89014-6620 7ei7R9Cen4x4S_fs2lxf7w ["Shopping","Food","Candy Stores","Chocolatier... 3 13 1/2/2015 5.0 ... 1 2 0 0 0 0 0 0 0 none
979 979 ObjectId(581151a4b6729e7e31343725) See's Candies 1300 W Sunset Rd Henderson 89014-6620 7ei7R9Cen4x4S_fs2lxf7w ["Shopping","Food","Candy Stores","Chocolatier... 3 13 2/10/2016 5.0 ... 1 2 0 0 0 0 0 0 0 none
980 980 ObjectId(581151a4b6729e7e31343725) See's Candies 1300 W Sunset Rd Henderson 89014-6620 7ei7R9Cen4x4S_fs2lxf7w ["Shopping","Food","Candy Stores","Chocolatier... 3 13 2/10/2016 5.0 ... 1 2 0 0 0 0 0 0 0 none
981 981 ObjectId(581151a4b6729e7e31343744) Coyote's Cafe & Cantina 4350 E Sunset Rd Henderson 89014-2258 Nf2Vj8R6So6_jeX-YhAdJA ["Mexican","Restaurants"] 3 121 3/16/2010 4.0 ... 1 2 0 0 0 0 0 0 0 none
982 982 ObjectId(581151a4b6729e7e31343744) Coyote's Cafe & Cantina 4350 E Sunset Rd Henderson 89014-2258 Nf2Vj8R6So6_jeX-YhAdJA ["Mexican","Restaurants"] 3 121 3/16/2010 4.0 ... 1 2 0 0 0 0 0 0 0 none
983 983 ObjectId(581151a4b6729e7e31343744) Coyote's Cafe & Cantina 4350 E Sunset Rd Henderson 89014-2258 Nf2Vj8R6So6_jeX-YhAdJA ["Mexican","Restaurants"] 3 121 3/21/2010 4.0 ... 1 2 0 0 0 0 0 0 0 none
984 984 ObjectId(581151a4b6729e7e31343744) Coyote's Cafe & Cantina 4350 E Sunset Rd Henderson 89014-2258 Nf2Vj8R6So6_jeX-YhAdJA ["Mexican","Restaurants"] 3 121 3/21/2010 4.0 ... 1 2 0 0 0 0 0 0 0 none
985 985 ObjectId(581151a4b6729e7e31343744) Coyote's Cafe & Cantina 4350 E Sunset Rd Henderson 89014-2258 Nf2Vj8R6So6_jeX-YhAdJA ["Mexican","Restaurants"] 3 121 5/19/2011 4.0 ... 1 2 0 0 0 0 0 0 0 none
986 986 ObjectId(581151a4b6729e7e31343744) Coyote's Cafe & Cantina 4350 E Sunset Rd Henderson 89014-2258 Nf2Vj8R6So6_jeX-YhAdJA ["Mexican","Restaurants"] 3 121 5/19/2011 4.0 ... 1 2 0 0 0 0 0 0 0 none
987 987 ObjectId(581151a4b6729e7e31343744) Coyote's Cafe & Cantina 4350 E Sunset Rd Henderson 89014-2258 Nf2Vj8R6So6_jeX-YhAdJA ["Mexican","Restaurants"] 3 121 6/20/2012 4.0 ... 1 2 0 0 0 0 0 0 0 none
988 988 ObjectId(581151a4b6729e7e31343744) Coyote's Cafe & Cantina 4350 E Sunset Rd Henderson 89014-2258 Nf2Vj8R6So6_jeX-YhAdJA ["Mexican","Restaurants"] 3 121 6/20/2012 4.0 ... 1 2 0 0 0 0 0 0 0 none
989 989 ObjectId(581151a4b6729e7e31343744) Coyote's Cafe & Cantina 4350 E Sunset Rd Henderson 89014-2258 Nf2Vj8R6So6_jeX-YhAdJA ["Mexican","Restaurants"] 3 121 7/2/2012 4.0 ... 1 2 0 0 0 0 0 0 0 none
990 990 ObjectId(581151a4b6729e7e31343744) Coyote's Cafe & Cantina 4350 E Sunset Rd Henderson 89014-2258 Nf2Vj8R6So6_jeX-YhAdJA ["Mexican","Restaurants"] 3 121 7/2/2012 4.0 ... 1 2 0 0 0 0 0 0 0 none
991 991 ObjectId(581151a4b6729e7e31343744) Coyote's Cafe & Cantina 4350 E Sunset Rd Henderson 89014-2258 Nf2Vj8R6So6_jeX-YhAdJA ["Mexican","Restaurants"] 3 121 8/5/2013 4.0 ... 1 2 0 0 0 0 0 0 0 none
992 992 ObjectId(581151a4b6729e7e31343744) Coyote's Cafe & Cantina 4350 E Sunset Rd Henderson 89014-2258 Nf2Vj8R6So6_jeX-YhAdJA ["Mexican","Restaurants"] 3 121 8/5/2013 4.0 ... 1 2 0 0 0 0 0 0 0 none
993 993 ObjectId(581151a4b6729e7e31343744) Coyote's Cafe & Cantina 4350 E Sunset Rd Henderson 89014-2258 Nf2Vj8R6So6_jeX-YhAdJA ["Mexican","Restaurants"] 3 121 2/7/2014 4.0 ... 1 2 0 0 0 0 0 0 0 none
994 994 ObjectId(581151a4b6729e7e31343744) Coyote's Cafe & Cantina 4350 E Sunset Rd Henderson 89014-2258 Nf2Vj8R6So6_jeX-YhAdJA ["Mexican","Restaurants"] 3 121 2/7/2014 4.0 ... 1 2 0 0 0 0 0 0 0 none
995 995 ObjectId(581151a4b6729e7e31343744) Coyote's Cafe & Cantina 4350 E Sunset Rd Henderson 89014-2258 Nf2Vj8R6So6_jeX-YhAdJA ["Mexican","Restaurants"] 3 121 1/23/2015 4.0 ... 1 2 0 0 0 0 0 0 0 none
996 996 ObjectId(581151a4b6729e7e31343744) Coyote's Cafe & Cantina 4350 E Sunset Rd Henderson 89014-2258 Nf2Vj8R6So6_jeX-YhAdJA ["Mexican","Restaurants"] 3 121 1/23/2015 4.0 ... 1 2 0 0 0 0 0 0 0 none
997 997 ObjectId(581151a4b6729e7e31343744) Coyote's Cafe & Cantina 4350 E Sunset Rd Henderson 89014-2258 Nf2Vj8R6So6_jeX-YhAdJA ["Mexican","Restaurants"] 3 121 5/16/2016 4.0 ... 1 2 0 0 0 0 0 0 0 none
998 998 ObjectId(581151a4b6729e7e31343744) Coyote's Cafe & Cantina 4350 E Sunset Rd Henderson 89014-2258 Nf2Vj8R6So6_jeX-YhAdJA ["Mexican","Restaurants"] 3 121 5/16/2016 4.0 ... 1 2 0 0 0 0 0 0 0 none
999 999 ObjectId(581151a4b6729e7e31343744) Coyote's Cafe & Cantina 4350 E Sunset Rd Henderson 89014-2258 Nf2Vj8R6So6_jeX-YhAdJA ["Mexican","Restaurants"] 3 121 5/31/2016 4.0 ... 1 2 0 0 0 0 0 0 0 none

1000 rows × 63 columns


In [85]:
#Create city Dummy Variable - Boston: 1; Charlotte: 2; Las Vegas: 3
df_city = pd.get_dummies(df['city'])
df_new = pd.concat([df, df_city], axis=1)

In [86]:
df = df_new.rename(columns={1: "Boston", 2: "Charlotte", 3:"Las Vegas"})

df.head(10)


Out[86]:
Unnamed: 0 _id restaurant_name address_full business_id categories city review_count inspection_date stars ... tourist classy hipster latenight upscale divey Neighborhoods Boston Charlotte Las Vegas
0 0 ObjectId(581151a3b6729e7e313418da) TLC WINGS & GRILL 9101 PINEVILLE-MATTHEWS RD lX3XYcMWoRlHjrmkoGNefQ ["Chicken Wings","Restaurants"] 2 29 1/10/2012 4.0 ... 0 0 0 0 0 0 none 0.0 1.0 0.0
1 1 ObjectId(581151a3b6729e7e313418da) TLC WINGS & GRILL 9101 PINEVILLE-MATTHEWS RD lX3XYcMWoRlHjrmkoGNefQ ["Chicken Wings","Restaurants"] 2 29 4/20/2012 4.0 ... 0 0 0 0 0 0 none 0.0 1.0 0.0
2 2 ObjectId(581151a3b6729e7e313418da) TLC WINGS & GRILL 9101 PINEVILLE-MATTHEWS RD lX3XYcMWoRlHjrmkoGNefQ ["Chicken Wings","Restaurants"] 2 29 8/3/2012 4.0 ... 0 0 0 0 0 0 none 0.0 1.0 0.0
3 3 ObjectId(581151a3b6729e7e313418da) TLC WINGS & GRILL 9101 PINEVILLE-MATTHEWS RD lX3XYcMWoRlHjrmkoGNefQ ["Chicken Wings","Restaurants"] 2 29 1/24/2013 4.0 ... 0 0 0 0 0 0 none 0.0 1.0 0.0
4 4 ObjectId(581151a3b6729e7e313418da) TLC WINGS & GRILL 9101 PINEVILLE-MATTHEWS RD lX3XYcMWoRlHjrmkoGNefQ ["Chicken Wings","Restaurants"] 2 29 4/22/2013 4.0 ... 0 0 0 0 0 0 none 0.0 1.0 0.0
5 5 ObjectId(581151a3b6729e7e313418da) TLC WINGS & GRILL 9101 PINEVILLE-MATTHEWS RD lX3XYcMWoRlHjrmkoGNefQ ["Chicken Wings","Restaurants"] 2 29 10/4/2013 4.0 ... 0 0 0 0 0 0 none 0.0 1.0 0.0
6 6 ObjectId(581151a3b6729e7e313418da) TLC WINGS & GRILL 9101 PINEVILLE-MATTHEWS RD lX3XYcMWoRlHjrmkoGNefQ ["Chicken Wings","Restaurants"] 2 29 4/3/2014 4.0 ... 0 0 0 0 0 0 none 0.0 1.0 0.0
7 7 ObjectId(581151a3b6729e7e313418da) TLC WINGS & GRILL 9101 PINEVILLE-MATTHEWS RD lX3XYcMWoRlHjrmkoGNefQ ["Chicken Wings","Restaurants"] 2 29 1/9/2015 4.0 ... 0 0 0 0 0 0 none 0.0 1.0 0.0
8 8 ObjectId(581151a3b6729e7e313418da) TLC WINGS & GRILL 9101 PINEVILLE-MATTHEWS RD lX3XYcMWoRlHjrmkoGNefQ ["Chicken Wings","Restaurants"] 2 29 7/1/2015 4.0 ... 0 0 0 0 0 0 none 0.0 1.0 0.0
9 9 ObjectId(581151a3b6729e7e313418da) TLC WINGS & GRILL 9101 PINEVILLE-MATTHEWS RD lX3XYcMWoRlHjrmkoGNefQ ["Chicken Wings","Restaurants"] 2 29 2/3/2016 4.0 ... 0 0 0 0 0 0 none 0.0 1.0 0.0

10 rows × 66 columns


In [87]:
import pandas as pd
from sklearn import preprocessing

le = preprocessing.LabelEncoder()
label_neighbor = pd.DataFrame(le.fit_transform(df.Neighborhoods))
neighborhood = pd.concat([df.Neighborhoods, label_neighbor], axis=1)

def bin_convert(x):
    binary = '{0:07b}'.format(x)
    return binary

neighborhood['binary'] = neighborhood[0].apply(bin_convert)
neighborhood_bin = neighborhood['binary'].apply(lambda x: pd.Series(list(x)))
neighborhood_bin.columns = ['neighborhood'+str(x) for x in neighborhood_bin.columns]
df_new = pd.concat([df, neighborhood_bin], axis=1)

In [88]:
df_new.head(100)


Out[88]:
Unnamed: 0 _id restaurant_name address_full business_id categories city review_count inspection_date stars ... Boston Charlotte Las Vegas neighborhood0 neighborhood1 neighborhood2 neighborhood3 neighborhood4 neighborhood5 neighborhood6
0 0 ObjectId(581151a3b6729e7e313418da) TLC WINGS & GRILL 9101 PINEVILLE-MATTHEWS RD lX3XYcMWoRlHjrmkoGNefQ ["Chicken Wings","Restaurants"] 2 29 1/10/2012 4.0 ... 0.0 1.0 0.0 0 1 1 1 1 0 0
1 1 ObjectId(581151a3b6729e7e313418da) TLC WINGS & GRILL 9101 PINEVILLE-MATTHEWS RD lX3XYcMWoRlHjrmkoGNefQ ["Chicken Wings","Restaurants"] 2 29 4/20/2012 4.0 ... 0.0 1.0 0.0 0 1 1 1 1 0 0
2 2 ObjectId(581151a3b6729e7e313418da) TLC WINGS & GRILL 9101 PINEVILLE-MATTHEWS RD lX3XYcMWoRlHjrmkoGNefQ ["Chicken Wings","Restaurants"] 2 29 8/3/2012 4.0 ... 0.0 1.0 0.0 0 1 1 1 1 0 0
3 3 ObjectId(581151a3b6729e7e313418da) TLC WINGS & GRILL 9101 PINEVILLE-MATTHEWS RD lX3XYcMWoRlHjrmkoGNefQ ["Chicken Wings","Restaurants"] 2 29 1/24/2013 4.0 ... 0.0 1.0 0.0 0 1 1 1 1 0 0
4 4 ObjectId(581151a3b6729e7e313418da) TLC WINGS & GRILL 9101 PINEVILLE-MATTHEWS RD lX3XYcMWoRlHjrmkoGNefQ ["Chicken Wings","Restaurants"] 2 29 4/22/2013 4.0 ... 0.0 1.0 0.0 0 1 1 1 1 0 0
5 5 ObjectId(581151a3b6729e7e313418da) TLC WINGS & GRILL 9101 PINEVILLE-MATTHEWS RD lX3XYcMWoRlHjrmkoGNefQ ["Chicken Wings","Restaurants"] 2 29 10/4/2013 4.0 ... 0.0 1.0 0.0 0 1 1 1 1 0 0
6 6 ObjectId(581151a3b6729e7e313418da) TLC WINGS & GRILL 9101 PINEVILLE-MATTHEWS RD lX3XYcMWoRlHjrmkoGNefQ ["Chicken Wings","Restaurants"] 2 29 4/3/2014 4.0 ... 0.0 1.0 0.0 0 1 1 1 1 0 0
7 7 ObjectId(581151a3b6729e7e313418da) TLC WINGS & GRILL 9101 PINEVILLE-MATTHEWS RD lX3XYcMWoRlHjrmkoGNefQ ["Chicken Wings","Restaurants"] 2 29 1/9/2015 4.0 ... 0.0 1.0 0.0 0 1 1 1 1 0 0
8 8 ObjectId(581151a3b6729e7e313418da) TLC WINGS & GRILL 9101 PINEVILLE-MATTHEWS RD lX3XYcMWoRlHjrmkoGNefQ ["Chicken Wings","Restaurants"] 2 29 7/1/2015 4.0 ... 0.0 1.0 0.0 0 1 1 1 1 0 0
9 9 ObjectId(581151a3b6729e7e313418da) TLC WINGS & GRILL 9101 PINEVILLE-MATTHEWS RD lX3XYcMWoRlHjrmkoGNefQ ["Chicken Wings","Restaurants"] 2 29 2/3/2016 4.0 ... 0.0 1.0 0.0 0 1 1 1 1 0 0
10 10 ObjectId(581151a3b6729e7e313418da) TLC WINGS & GRILL 9101 PINEVILLE-MATTHEWS RD lX3XYcMWoRlHjrmkoGNefQ ["Chicken Wings","Restaurants"] 2 29 8/15/2016 4.0 ... 0.0 1.0 0.0 0 1 1 1 1 0 0
11 11 ObjectId(581151a3b6729e7e313418e2) COMFORT SUITES 10415 CENTRUM PARKWAY ljk9LMGlc8ItupjrSKBoRg ["Hotels \u0026 Travel","Event Planning \u0026... 2 10 4/17/2012 4.0 ... 0.0 1.0 0.0 0 1 1 1 1 0 0
12 12 ObjectId(581151a3b6729e7e313418e2) COMFORT SUITES 10415 CENTRUM PARKWAY ljk9LMGlc8ItupjrSKBoRg ["Hotels \u0026 Travel","Event Planning \u0026... 2 10 12/27/2012 4.0 ... 0.0 1.0 0.0 0 1 1 1 1 0 0
13 13 ObjectId(581151a3b6729e7e313418f6) WALDHORN RESTAURANT 12101 LANCASTER HIGHWAY 2_0P2AmSSFtPgddio0MgYA ["German","Restaurants"] 2 175 3/16/2012 5.0 ... 0.0 1.0 0.0 0 1 1 1 1 0 0
14 14 ObjectId(581151a3b6729e7e313418f6) WALDHORN RESTAURANT 12101 LANCASTER HIGHWAY 2_0P2AmSSFtPgddio0MgYA ["German","Restaurants"] 2 175 6/21/2012 5.0 ... 0.0 1.0 0.0 0 1 1 1 1 0 0
15 15 ObjectId(581151a3b6729e7e313418f6) WALDHORN RESTAURANT 12101 LANCASTER HIGHWAY 2_0P2AmSSFtPgddio0MgYA ["German","Restaurants"] 2 175 11/2/2012 5.0 ... 0.0 1.0 0.0 0 1 1 1 1 0 0
16 16 ObjectId(581151a3b6729e7e313418f6) WALDHORN RESTAURANT 12101 LANCASTER HIGHWAY 2_0P2AmSSFtPgddio0MgYA ["German","Restaurants"] 2 175 3/20/2013 5.0 ... 0.0 1.0 0.0 0 1 1 1 1 0 0
17 17 ObjectId(581151a3b6729e7e313418f6) WALDHORN RESTAURANT 12101 LANCASTER HIGHWAY 2_0P2AmSSFtPgddio0MgYA ["German","Restaurants"] 2 175 8/8/2013 5.0 ... 0.0 1.0 0.0 0 1 1 1 1 0 0
18 18 ObjectId(581151a3b6729e7e313418f6) WALDHORN RESTAURANT 12101 LANCASTER HIGHWAY 2_0P2AmSSFtPgddio0MgYA ["German","Restaurants"] 2 175 4/2/2014 5.0 ... 0.0 1.0 0.0 0 1 1 1 1 0 0
19 19 ObjectId(581151a3b6729e7e313418f6) WALDHORN RESTAURANT 12101 LANCASTER HIGHWAY 2_0P2AmSSFtPgddio0MgYA ["German","Restaurants"] 2 175 9/19/2014 5.0 ... 0.0 1.0 0.0 0 1 1 1 1 0 0
20 20 ObjectId(581151a3b6729e7e313418f6) WALDHORN RESTAURANT 12101 LANCASTER HIGHWAY 2_0P2AmSSFtPgddio0MgYA ["German","Restaurants"] 2 175 3/12/2015 5.0 ... 0.0 1.0 0.0 0 1 1 1 1 0 0
21 21 ObjectId(581151a3b6729e7e313418f6) WALDHORN RESTAURANT 12101 LANCASTER HIGHWAY 2_0P2AmSSFtPgddio0MgYA ["German","Restaurants"] 2 175 7/29/2015 5.0 ... 0.0 1.0 0.0 0 1 1 1 1 0 0
22 22 ObjectId(581151a3b6729e7e313418f6) WALDHORN RESTAURANT 12101 LANCASTER HIGHWAY 2_0P2AmSSFtPgddio0MgYA ["German","Restaurants"] 2 175 12/11/2015 5.0 ... 0.0 1.0 0.0 0 1 1 1 1 0 0
23 23 ObjectId(581151a3b6729e7e313418f6) WALDHORN RESTAURANT 12101 LANCASTER HIGHWAY 2_0P2AmSSFtPgddio0MgYA ["German","Restaurants"] 2 175 3/30/2016 5.0 ... 0.0 1.0 0.0 0 1 1 1 1 0 0
24 24 ObjectId(581151a3b6729e7e313418f6) WALDHORN RESTAURANT 12101 LANCASTER HIGHWAY 2_0P2AmSSFtPgddio0MgYA ["German","Restaurants"] 2 175 6/30/2016 5.0 ... 0.0 1.0 0.0 0 1 1 1 1 0 0
25 25 ObjectId(581151a3b6729e7e313418f6) WALDHORN RESTAURANT 12101 LANCASTER HIGHWAY 2_0P2AmSSFtPgddio0MgYA ["German","Restaurants"] 2 175 9/28/2016 5.0 ... 0.0 1.0 0.0 0 1 1 1 1 0 0
26 26 ObjectId(581151a3b6729e7e3134191d) CHINA BUFFET 9931 LEE ST 5p3Tqyp19UowO0-dAFvxMw ["Buffets","Chinese","Restaurants"] 2 38 3/29/2012 3.0 ... 0.0 1.0 0.0 0 1 1 1 1 0 0
27 27 ObjectId(581151a3b6729e7e3134191d) CHINA BUFFET 9931 LEE ST 5p3Tqyp19UowO0-dAFvxMw ["Buffets","Chinese","Restaurants"] 2 38 6/27/2012 3.0 ... 0.0 1.0 0.0 0 1 1 1 1 0 0
28 28 ObjectId(581151a3b6729e7e3134191d) CHINA BUFFET 9931 LEE ST 5p3Tqyp19UowO0-dAFvxMw ["Buffets","Chinese","Restaurants"] 2 38 10/26/2012 3.0 ... 0.0 1.0 0.0 0 1 1 1 1 0 0
29 29 ObjectId(581151a3b6729e7e3134191d) CHINA BUFFET 9931 LEE ST 5p3Tqyp19UowO0-dAFvxMw ["Buffets","Chinese","Restaurants"] 2 38 3/28/2013 3.0 ... 0.0 1.0 0.0 0 1 1 1 1 0 0
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
70 70 ObjectId(581151a3b6729e7e31341939) SOHO BISTRO 214 N TRYON ST rT-iPtIXMKj3dTcl87lbOw ["Chinese","Restaurants"] 2 114 5/30/2014 4.0 ... 0.0 1.0 0.0 0 0 1 0 1 1 1
71 71 ObjectId(581151a3b6729e7e31341939) SOHO BISTRO 214 N TRYON ST rT-iPtIXMKj3dTcl87lbOw ["Chinese","Restaurants"] 2 114 10/30/2014 4.0 ... 0.0 1.0 0.0 0 0 1 0 1 1 1
72 72 ObjectId(581151a3b6729e7e31341939) SOHO BISTRO 214 N TRYON ST rT-iPtIXMKj3dTcl87lbOw ["Chinese","Restaurants"] 2 114 2/23/2015 4.0 ... 0.0 1.0 0.0 0 0 1 0 1 1 1
73 73 ObjectId(581151a3b6729e7e31341939) SOHO BISTRO 214 N TRYON ST rT-iPtIXMKj3dTcl87lbOw ["Chinese","Restaurants"] 2 114 6/30/2015 4.0 ... 0.0 1.0 0.0 0 0 1 0 1 1 1
74 74 ObjectId(581151a3b6729e7e31341939) SOHO BISTRO 214 N TRYON ST rT-iPtIXMKj3dTcl87lbOw ["Chinese","Restaurants"] 2 114 9/22/2015 4.0 ... 0.0 1.0 0.0 0 0 1 0 1 1 1
75 75 ObjectId(581151a3b6729e7e31341939) SOHO BISTRO 214 N TRYON ST rT-iPtIXMKj3dTcl87lbOw ["Chinese","Restaurants"] 2 114 12/2/2015 4.0 ... 0.0 1.0 0.0 0 0 1 0 1 1 1
76 76 ObjectId(581151a3b6729e7e31341939) SOHO BISTRO 214 N TRYON ST rT-iPtIXMKj3dTcl87lbOw ["Chinese","Restaurants"] 2 114 3/11/2016 4.0 ... 0.0 1.0 0.0 0 0 1 0 1 1 1
77 77 ObjectId(581151a3b6729e7e31341939) SOHO BISTRO 214 N TRYON ST rT-iPtIXMKj3dTcl87lbOw ["Chinese","Restaurants"] 2 114 5/25/2016 4.0 ... 0.0 1.0 0.0 0 0 1 0 1 1 1
78 78 ObjectId(581151a3b6729e7e31341939) SOHO BISTRO 214 N TRYON ST rT-iPtIXMKj3dTcl87lbOw ["Chinese","Restaurants"] 2 114 9/28/2016 4.0 ... 0.0 1.0 0.0 0 0 1 0 1 1 1
79 79 ObjectId(581151a3b6729e7e31341947) SIMMONS RESTAURANT 516 N GRAHAM ST XzhsJecsCYj-Wc32zOWqmg ["Southern","Restaurants"] 2 15 6/4/2012 4.0 ... 0.0 1.0 0.0 0 0 1 1 0 0 0
80 80 ObjectId(581151a3b6729e7e31341947) SIMMONS RESTAURANT 516 N GRAHAM ST XzhsJecsCYj-Wc32zOWqmg ["Southern","Restaurants"] 2 15 10/31/2012 4.0 ... 0.0 1.0 0.0 0 0 1 1 0 0 0
81 81 ObjectId(581151a3b6729e7e31341947) SIMMONS RESTAURANT 516 N GRAHAM ST XzhsJecsCYj-Wc32zOWqmg ["Southern","Restaurants"] 2 15 2/28/2013 4.0 ... 0.0 1.0 0.0 0 0 1 1 0 0 0
82 82 ObjectId(581151a3b6729e7e31341947) SIMMONS RESTAURANT 516 N GRAHAM ST XzhsJecsCYj-Wc32zOWqmg ["Southern","Restaurants"] 2 15 3/3/2014 4.0 ... 0.0 1.0 0.0 0 0 1 1 0 0 0
83 83 ObjectId(581151a3b6729e7e31341948) FUJIYAMA 320 S TRYON ST QMX1ssofSveU3qhVAKLnXA ["Korean","Seafood","Japanese","Restaurants"] 2 14 2/28/2012 4.0 ... 0.0 1.0 0.0 0 1 1 0 1 1 1
84 84 ObjectId(581151a3b6729e7e31341948) FUJIYAMA 320 S TRYON ST QMX1ssofSveU3qhVAKLnXA ["Korean","Seafood","Japanese","Restaurants"] 2 14 7/20/2012 4.0 ... 0.0 1.0 0.0 0 1 1 0 1 1 1
85 85 ObjectId(581151a3b6729e7e31341948) FUJIYAMA 320 S TRYON ST QMX1ssofSveU3qhVAKLnXA ["Korean","Seafood","Japanese","Restaurants"] 2 14 1/31/2013 4.0 ... 0.0 1.0 0.0 0 1 1 0 1 1 1
86 86 ObjectId(581151a3b6729e7e31341948) FUJIYAMA 320 S TRYON ST QMX1ssofSveU3qhVAKLnXA ["Korean","Seafood","Japanese","Restaurants"] 2 14 3/25/2013 4.0 ... 0.0 1.0 0.0 0 1 1 0 1 1 1
87 87 ObjectId(581151a3b6729e7e31341948) FUJIYAMA 320 S TRYON ST QMX1ssofSveU3qhVAKLnXA ["Korean","Seafood","Japanese","Restaurants"] 2 14 3/20/2014 4.0 ... 0.0 1.0 0.0 0 1 1 0 1 1 1
88 88 ObjectId(581151a3b6729e7e31341948) FUJIYAMA 320 S TRYON ST QMX1ssofSveU3qhVAKLnXA ["Korean","Seafood","Japanese","Restaurants"] 2 14 8/15/2014 4.0 ... 0.0 1.0 0.0 0 1 1 0 1 1 1
89 89 ObjectId(581151a3b6729e7e31341948) FUJIYAMA 320 S TRYON ST QMX1ssofSveU3qhVAKLnXA ["Korean","Seafood","Japanese","Restaurants"] 2 14 12/22/2014 4.0 ... 0.0 1.0 0.0 0 1 1 0 1 1 1
90 90 ObjectId(581151a3b6729e7e31341948) FUJIYAMA 320 S TRYON ST QMX1ssofSveU3qhVAKLnXA ["Korean","Seafood","Japanese","Restaurants"] 2 14 4/17/2015 4.0 ... 0.0 1.0 0.0 0 1 1 0 1 1 1
91 91 ObjectId(581151a3b6729e7e31341948) FUJIYAMA 320 S TRYON ST QMX1ssofSveU3qhVAKLnXA ["Korean","Seafood","Japanese","Restaurants"] 2 14 9/21/2015 4.0 ... 0.0 1.0 0.0 0 1 1 0 1 1 1
92 92 ObjectId(581151a3b6729e7e31341948) FUJIYAMA 320 S TRYON ST QMX1ssofSveU3qhVAKLnXA ["Korean","Seafood","Japanese","Restaurants"] 2 14 1/26/2016 4.0 ... 0.0 1.0 0.0 0 1 1 0 1 1 1
93 93 ObjectId(581151a3b6729e7e31341948) FUJIYAMA 320 S TRYON ST QMX1ssofSveU3qhVAKLnXA ["Korean","Seafood","Japanese","Restaurants"] 2 14 4/11/2016 4.0 ... 0.0 1.0 0.0 0 1 1 0 1 1 1
94 94 ObjectId(581151a3b6729e7e31341948) FUJIYAMA 320 S TRYON ST QMX1ssofSveU3qhVAKLnXA ["Korean","Seafood","Japanese","Restaurants"] 2 14 8/19/2016 4.0 ... 0.0 1.0 0.0 0 1 1 0 1 1 1
95 95 ObjectId(581151a3b6729e7e3134194a) CHINA KING 128 BREVARD CT utyqO_IVBAN8ULZmi52XaA ["Chinese","Restaurants"] 2 6 3/27/2012 3.0 ... 0.0 1.0 0.0 0 1 1 0 1 1 1
96 96 ObjectId(581151a3b6729e7e3134194a) CHINA KING 128 BREVARD CT utyqO_IVBAN8ULZmi52XaA ["Chinese","Restaurants"] 2 6 5/23/2012 3.0 ... 0.0 1.0 0.0 0 1 1 0 1 1 1
97 97 ObjectId(581151a3b6729e7e3134194a) CHINA KING 128 BREVARD CT utyqO_IVBAN8ULZmi52XaA ["Chinese","Restaurants"] 2 6 8/9/2012 3.0 ... 0.0 1.0 0.0 0 1 1 0 1 1 1
98 98 ObjectId(581151a3b6729e7e3134194a) CHINA KING 128 BREVARD CT utyqO_IVBAN8ULZmi52XaA ["Chinese","Restaurants"] 2 6 3/7/2013 3.0 ... 0.0 1.0 0.0 0 1 1 0 1 1 1
99 99 ObjectId(581151a3b6729e7e3134194a) CHINA KING 128 BREVARD CT utyqO_IVBAN8ULZmi52XaA ["Chinese","Restaurants"] 2 6 5/20/2013 3.0 ... 0.0 1.0 0.0 0 1 1 0 1 1 1

100 rows × 73 columns


In [89]:
#Create Cross-Referenced DF for Neighborhood Lookup                     
CRdf = df_new.copy() 

CRdf = CRdf[['business_id', 'Neighborhoods', 'neighborhood0', 'neighborhood1', 'neighborhood2', 'neighborhood3', 'neighborhood4', 'neighborhood5', 'neighborhood6']]
CRdf.head(10)


Out[89]:
business_id Neighborhoods neighborhood0 neighborhood1 neighborhood2 neighborhood3 neighborhood4 neighborhood5 neighborhood6
0 lX3XYcMWoRlHjrmkoGNefQ none 0 1 1 1 1 0 0
1 lX3XYcMWoRlHjrmkoGNefQ none 0 1 1 1 1 0 0
2 lX3XYcMWoRlHjrmkoGNefQ none 0 1 1 1 1 0 0
3 lX3XYcMWoRlHjrmkoGNefQ none 0 1 1 1 1 0 0
4 lX3XYcMWoRlHjrmkoGNefQ none 0 1 1 1 1 0 0
5 lX3XYcMWoRlHjrmkoGNefQ none 0 1 1 1 1 0 0
6 lX3XYcMWoRlHjrmkoGNefQ none 0 1 1 1 1 0 0
7 lX3XYcMWoRlHjrmkoGNefQ none 0 1 1 1 1 0 0
8 lX3XYcMWoRlHjrmkoGNefQ none 0 1 1 1 1 0 0
9 lX3XYcMWoRlHjrmkoGNefQ none 0 1 1 1 1 0 0

In [90]:
#Drop string columns already encoded
del df_new['neighborhoods']
del df_new['attributes']
del df_new['categories']
del df_new['open']
del df_new['city']

In [91]:
df_new.head(10)


Out[91]:
Unnamed: 0 _id restaurant_name address_full business_id review_count inspection_date stars latitude longitude ... Boston Charlotte Las Vegas neighborhood0 neighborhood1 neighborhood2 neighborhood3 neighborhood4 neighborhood5 neighborhood6
0 0 ObjectId(581151a3b6729e7e313418da) TLC WINGS & GRILL 9101 PINEVILLE-MATTHEWS RD lX3XYcMWoRlHjrmkoGNefQ 29 1/10/2012 4.0 35.0 -81.0 ... 0.0 1.0 0.0 0 1 1 1 1 0 0
1 1 ObjectId(581151a3b6729e7e313418da) TLC WINGS & GRILL 9101 PINEVILLE-MATTHEWS RD lX3XYcMWoRlHjrmkoGNefQ 29 4/20/2012 4.0 35.0 -81.0 ... 0.0 1.0 0.0 0 1 1 1 1 0 0
2 2 ObjectId(581151a3b6729e7e313418da) TLC WINGS & GRILL 9101 PINEVILLE-MATTHEWS RD lX3XYcMWoRlHjrmkoGNefQ 29 8/3/2012 4.0 35.0 -81.0 ... 0.0 1.0 0.0 0 1 1 1 1 0 0
3 3 ObjectId(581151a3b6729e7e313418da) TLC WINGS & GRILL 9101 PINEVILLE-MATTHEWS RD lX3XYcMWoRlHjrmkoGNefQ 29 1/24/2013 4.0 35.0 -81.0 ... 0.0 1.0 0.0 0 1 1 1 1 0 0
4 4 ObjectId(581151a3b6729e7e313418da) TLC WINGS & GRILL 9101 PINEVILLE-MATTHEWS RD lX3XYcMWoRlHjrmkoGNefQ 29 4/22/2013 4.0 35.0 -81.0 ... 0.0 1.0 0.0 0 1 1 1 1 0 0
5 5 ObjectId(581151a3b6729e7e313418da) TLC WINGS & GRILL 9101 PINEVILLE-MATTHEWS RD lX3XYcMWoRlHjrmkoGNefQ 29 10/4/2013 4.0 35.0 -81.0 ... 0.0 1.0 0.0 0 1 1 1 1 0 0
6 6 ObjectId(581151a3b6729e7e313418da) TLC WINGS & GRILL 9101 PINEVILLE-MATTHEWS RD lX3XYcMWoRlHjrmkoGNefQ 29 4/3/2014 4.0 35.0 -81.0 ... 0.0 1.0 0.0 0 1 1 1 1 0 0
7 7 ObjectId(581151a3b6729e7e313418da) TLC WINGS & GRILL 9101 PINEVILLE-MATTHEWS RD lX3XYcMWoRlHjrmkoGNefQ 29 1/9/2015 4.0 35.0 -81.0 ... 0.0 1.0 0.0 0 1 1 1 1 0 0
8 8 ObjectId(581151a3b6729e7e313418da) TLC WINGS & GRILL 9101 PINEVILLE-MATTHEWS RD lX3XYcMWoRlHjrmkoGNefQ 29 7/1/2015 4.0 35.0 -81.0 ... 0.0 1.0 0.0 0 1 1 1 1 0 0
9 9 ObjectId(581151a3b6729e7e313418da) TLC WINGS & GRILL 9101 PINEVILLE-MATTHEWS RD lX3XYcMWoRlHjrmkoGNefQ 29 2/3/2016 4.0 35.0 -81.0 ... 0.0 1.0 0.0 0 1 1 1 1 0 0

10 rows × 68 columns


In [93]:
df_new.to_csv('the_final_countdown2.csv')
CRdf.to_csv('CRdata.csv')

In [ ]: