-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzomato.py
271 lines (203 loc) · 6.6 KB
/
zomato.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# -*- coding: utf-8 -*-
"""zomato.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1uHBrdBRb53m7drIcxqjCJxgwjwCXavrR
"""
import numpy as np
import pandas as pd
import warnings
warnings.filterwarnings('ignore')
import matplotlib.pyplot as plt
import seaborn as sns
data=pd.read_csv("zomato.csv",encoding='latin-1')
data.head()
data['Cuisines'].value_counts()
data=data.rename(columns={'Restaurant ID':'Restaurant ID'})
data.head()
data.info()
data['Is delivering now'].value_counts()
data.isnull().sum()
data.shape
data['Average Cost for two'].describe()
country=pd.read_excel("Country-Code.xlsx")
country
df=pd.merge(data,country,on="Country Code",how="left")
df.head()
!pip install plotly
countrys=df['Country'].value_counts()
country=pd.DataFrame(countrys).reset_index()
country.columns=['Country','Count']
country
country.loc[country['Count']<400,'Country']='Others'
country
country=country.groupby('Country').agg({'Count':'sum'})
country
from pickle import TRUE
# making pie chart for country wise distributuion
import plotly.express as px
from plotly.offline import init_notebook_mode, plot, iplot
labels = list(country.index)
values = list(country.Count)
# labels gives names and values gives count
fig = {
"data":[
{
"labels" : labels,
"values" : values,
"hoverinfo" : 'label+percent',
"domain": {"x": [0.5,0.5]},
"hole" : 0.6,
"type" : "pie",
"rotation":120,
},
],
"layout": {
"title" : "Restaurants Density Presence around the World",
"annotations": [
{
"font": {"size":20},
"showarrow": True,
"text": "Countries",
"x":0.2,
"y":0.9,
},
],
"autosize" : False,
}
}
iplot(fig)
# making pie chart for country wise distributuion
import plotly.express as px
from plotly.offline import init_notebook_mode, plot, iplot
labels = list(df.Country.value_counts().index)
values = list(df.Country.value_counts().values)
# labels gives names and values gives count
fig = {
"data":[
{
"labels" : labels,
"values" : values,
"hoverinfo" : 'label+percent',
"domain": {"x": [0, .9]},
"hole" : 0.6,
"type" : "pie",
"rotation":120,
},
],
"layout": {
"title" : "Restaurants Density Presence around the World",
"annotations": [
{
"font": {"size":20},
"showarrow": True,
"text": "Countries",
"x":0.2,
"y":0.9,
},
],
"autosize" : False ,
}
}
iplot(fig)
#rating=df.groupby(['Aggregate rating','Rating color','Rating text']).size().reset_index().rename(columns={0:"Rating Count"})
#rating.head()
ratings=df.groupby(['Rating text']).agg({'Aggregate rating':'count'}).rename(columns={'Aggregate rating': 'count'})
ratings
plt.figure(figsize=(12,6))
# plt.xticks(rotation=75)
plt.title('Rating Text')
sns.barplot(x=ratings.index, y=ratings['count']);
india=df[df['Country']=='India']
india.head()
india.Cuisines.value_counts()
india['Is delivering now'].value_counts()
new=india[india['Is delivering now']=='Yes']
zomato=new.groupby(['City']).agg({'Aggregate rating':'count'}).rename(columns={'Aggregate rating': 'count'})
zomato
plt.figure(figsize=(12,6))
# plt.xticks(rotation=75)
plt.title('City with Zomato delivery ')
sns.barplot(x=zomato.index, y=zomato['count']);
india.isnull().sum()
citys=india['City'].value_counts()
city=pd.DataFrame(citys).reset_index()
city.columns=['City','Count']
city
city.loc[city['Count']<250,'City']='Others'
city
city=city.groupby('City').agg({'Count':'sum'})
city
labels = list(city.index)
values = list(city.Count)
# labels gives names and values gives count
fig = {
"data":[
{
"labels" : labels,
"values" : values,
"hoverinfo" : 'label+percent',
"domain": {"x": [0, .9]},
"hole" : 0.6,
"type" : "pie",
"rotation":120,
},
],
"layout": {
"title" : "Restaurants Density Presence in India",
"annotations": [
{
"font": {"size":20},
"showarrow": True,
"text": "Cities",
"x":0.2,
"y":0.9,
},
],
"autosize" : False ,
}
}
iplot(fig)
delhi=india[(india.City=="New Delhi")]
plt.figure(figsize=(12,6))
sns.barplot(x=delhi.Locality.value_counts().head(10),y=delhi.Locality.value_counts().head(10).index)
plt.ylabel(None)
plt.xlabel("Number of restaurants")
plt.title("Restaurants-Area Listing in New Delhi")
now=delhi[delhi['Is delivering now']=='Yes'][['Restaurant Name','Locality','Cuisines','Rating text']].sort_values(by='Rating text').reset_index()
now
cp=delhi[delhi.Locality=='Connaught Place']
cp.head()
ratings1=cp.groupby(['Rating text']).agg({'Aggregate rating':'count'}).rename(columns={'Aggregate rating': 'count'})
ratings1
plt.figure(figsize=(12,6))
# plt.xticks(rotation=75)
plt.title('Rating Text')
sns.barplot(x=ratings1.index, y=ratings1['count']);
cp['Average Cost for two'].value_counts()
cp['Average Cost for two'].describe()
cp['Is delivering now'].value_counts()
cp['Has Online delivery'].value_counts()
cp['Has Table booking'].value_counts()
# Top 5 Restaurants in CP
top=cp[cp["Rating text"].isin(['Excellent','Very Good'])].sort_values(by='Rating text').reset_index()
top[['Restaurant Name','Rating text','Cuisines','Average Cost for two']].head()
top=cp[cp["Rating text"].isin(['Excellent','Very Good','Good'])].sort_values(by='Rating text').reset_index()
top['Average Cost for two'].value_counts()
top.head()
top['Average Cost for two'].describe()
top.columns
top.shape
ph1=top[(top['Has Table booking']=='Yes') & (top['Has Online delivery']=='Yes')]
ph1[['Restaurant Name','Cuisines', 'Average Cost for two']]
len(ph1)
ph2=top[(top['Has Online delivery']=='No') | (top['Has Table booking']=='No')]
ph2[['Restaurant Name','Cuisines', 'Average Cost for two']]
top
tail=cp[cp['Rating text'].isin(['Average','Not rated'])].sort_values(by='Rating text').reset_index()
len(tail)
tail[['Restaurant Name','Cuisines', 'Average Cost for two']]
ph3=tail[(tail['Has Table booking']=='Yes') & (tail['Has Online delivery']=='Yes')]
ph3[['Restaurant Name','Cuisines', 'Average Cost for two']]
ph4=tail[(tail['Has Table booking']=='No') | (tail['Has Online delivery']=='No')]
ph4[['Restaurant Name','Cuisines', 'Average Cost for two']]