In [1]:
import pandas as pd
df = pd.read_csv('the_final_countdown2.csv', sep=",", encoding = 'utf-8', engine = 'python')
In [7]:
ChangeInViolations = [0]
for i in range(1,len(df)):
x = i
y = x-1
if df.iloc[x,1] == df.iloc[y,1]:
v = df.iloc[x,14] - df.iloc[y,14]
ChangeInViolations.append(v)
else:
ChangeInViolations.append(0)
In [8]:
ChangeInViolations = pd.Series(ChangeInViolations)
df['ChangeInViolations'] = ChangeInViolations.values
In [9]:
Asian = ['Szechuan','Cantonese','Hot Pot','Malaysian','Shanghainese','Singaporean','Cambodian','Mongolian',
'Teppanyaki','Ramen','Taiwanese','Traditional Chinese','Thai','Vietnamese','Korean','Japanese','Chinese','Oriental']
French = ['French']
Sandwiches = ['Sandwiches']
FastFood = ['Fast Food']
Burgers = ['Burgers']
Italian = ['Italian']
Hawaiian = ['Hawaiian']
Southern = ['Southern']
Mexican = ['Mexican','New Mexican Cuisine']
LatinAmerican = ['Latin-American']
MiddleEastern = ['Middle Eastern']
Greek = ['Greek']
American= ['American (Traditional)','American (New)']
Donuts = ['Donuts']
Indian =['Indian']
Seafood = ['Seafood']
Desserts = ['Desserts']
Salad = ['Salad']
Pizza = ['Pizza']
In [10]:
ct = [Asian,French,Sandwiches,FastFood,Burgers,Italian,Hawaiian,Southern,Mexican,LatinAmerican,
MiddleEastern,Greek,American,Donuts,Indian,Seafood,Desserts,Salad,Pizza]
In [11]:
def cuisineType(z):
columnName = []
for i in range(len(df)):
y = 0
for x in z:
if x in df.iloc[i,4]:
columnName.append(1)
break
else:
y += 1
if y == len(z):
columnName.append(0)
return columnName
In [12]:
colname = 1
for Type in ct:
newcol = cuisineType(Type)
newcol = pd.Series(newcol)
df[colname] = newcol.values
colname += 1
In [13]:
df.rename(columns ={1:"IsAsian",2:'IsFrench',3:'IsSandwiches',4:'IsFastFood',5:'IsBurgers',6:'IsItalian',7:'IsHawaiian',
8:'IsSouthern',9:'IsMexican',10:'IsLatinAmerican',11:'IsMiddleEastern',12:'IsGreek',13:'IsAmerican',
14:'IsDonuts',15:'IsIndian',16:'IsSeafood',17:'IsDesserts',18:'IsSalad',19:'Pizza'},inplace=True)
In [14]:
rt = ['Buffets','Sushi Bars','Delis','Sports Bars','Bakeries','Pubs','Caterers','Diners','Cafes','Bars']
In [15]:
def restaurantType(x):
restaurant = []
for i in range(len(df)):
if x in df.iloc[i,4]:
restaurant.append(1)
else:
restaurant.append(0)
return restaurant
In [16]:
for Type in rt:
colname = 'Is'+ Type
newcol = restaurantType(Type)
newcol = pd.Series(newcol)
df[colname] = newcol.values
In [17]:
df.to_csv('the_final_countdown_New.csv')
In [ ]:
In [ ]: