-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalysis-report1.py
More file actions
318 lines (151 loc) · 5.3 KB
/
analysis-report1.py
File metadata and controls
318 lines (151 loc) · 5.3 KB
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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
#!/usr/bin/env python
# coding: utf-8
# In[6]:
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import warnings
warnings.filterwarnings('ignore')
# In[7]:
#EDA (exploratry data anylysis ) and data cleaning
# In[9]:
df = pd.read_csv('C:\data anyliss\hotel_bookings 2.csv')
# In[10]:
df.head()
# In[11]:
df.tail()
# In[13]:
df.shape
# In[14]:
df.columns
# In[15]:
df.info
# In[16]:
df.info()
# In[17]:
df['reservation_status_date'] = pd.to_datetime(df['reservation_status_date'])
# In[18]:
df.info()
# In[19]:
df.describe(include = 'object')
# In[21]:
for col in df.describe(include = 'object').columns:
print(col)
print(df[col].unique())
print('-'*50)
# In[22]:
df.isnull().sum()
# In[25]:
df.drop(['company','agent'], axis = 1, inplace = True)
df.dropna(inplace = True)
# In[27]:
df.isnull().sum()
# In[28]:
df.dropna(inplace = True)
# In[30]:
df.isnull().sum()
# In[31]:
df.describe()
# In[32]:
df['adr'].plot(kind = 'box')
# In[33]:
df = df[df['adr']<5000]
# In[34]:
df.describe()
# In[37]:
#Data Analysis and Visualization
# In[44]:
cancelled_perc = df['is_canceled'].value_counts(normalize = True)
print(cancelled_perc)
plt.figure(figsize = (5,4))
plt.title('Reservation Status Count')
plt.bar(['Not cancelled','canceled'],df['is_canceled'].value_counts(), edgecolor = 'k', width = 0.7)
plt.show()
# In[52]:
plt.figure(figsize = (8,4))
ax1 = sns.countplot(x = 'hotel', hue = 'is_canceled', data = df, palette = 'Blues')
legend_labels,_ =ax1. get_legend_handles_labels()
ax1.legend(bbox_to_anchor=(1,1))
plt.title('Reservation status in different hotels' , size =20)
plt.xlabel('hotel')
plt.ylabel('number of reservations')
plt.legend(['not canceled' , 'cenceled'])
plt.show()
# In[53]:
#price of the city hotel and mantainence of the city hotel
# In[57]:
resort_hotel = df[df['hotel'] == 'Resort Hotel']
resort_hotel['is_canceled'].value_counts(normalize = True )
# In[58]:
city_hotel = df[df['hotel'] == 'City Hotel']
city_hotel['is_canceled'].value_counts(normalize = True )
# In[59]:
resort_hotel = resort_hotel.groupby('reservation_status_date')[['adr']].mean()
city_hotel = city_hotel.groupby('reservation_status_date')[['adr']].mean()
# In[60]:
plt.figure(figsize = (20,8))
plt.title('Average Daily Rate in City and Resort Hotel' , fontsize = 30)
plt.plot(resort_hotel.index, resort_hotel['adr'], label = 'Resort Hotel')
plt.plot(city_hotel.index, city_hotel['adr'], label = 'City Hotel')
plt.legend(fontsize = 20)
plt.show()
# In[62]:
df['month'] = df['reservation_status_date'].dt.month
plt.figure(figsize = (16,8))
ax1 = sns.countplot( x = 'month' , hue = 'is_canceled' , data = df , palette = 'bright')
legend_labels,_ = ax1. get_legend_handles_labels()
ax1.legend(bbox_to_anchor=(1,1))
plt.title('Reservation Status Per Month ' , size = 20)
plt.xlabel('Month')
plt.ylabel('number of reservations')
plt.legend(['not canceled','canceled'])
plt.show()
# In[65]:
plt.figure(figsize = (15,8))
plt.title('ADR per Month' , fontsize = 30)
sns.barplot('month', 'adr', data = df[df['is_canceled'] == 1].groupby('month')[['adr']].sum().reset_index())
plt.legend(fontsize = 20)
plt.show()
# In[68]:
plt.figure(figsize = (15,8))
plt.title('ADR per month' , fontsize = 30)
sns.barplot('month', 'adr', data = df[df['is_canceled'] == 1].groupby('month')[['adr']].sum().reset_index())
plt.legend(fontsize = 30)
plt.show()
# In[72]:
cancelled_data = df[df['is_canceled'] == 1]
top_10_country = cancelled_data['country'].value_counts()[:10]
plt.figure(figsize = (8,8))
plt.title('top 10 countaries with reservation canceled ')
plt.pie(top_10_country , autopct = '%.2f',labels = top_10_country.index)
plt.show()
# In[73]:
df['market_segment'].value_counts()
# In[74]:
df['market_segment'].value_counts(normalize = True)
# In[76]:
cancelled_data['market_segment'].value_counts(normalize = True)
# In[86]:
cancelled_df_adr = cancelled_data.groupby('reservation_status_date')[['adr']].mean()
cancelled_df_adr.reset_index(inplace = True)
cancelled_df_adr.sort_values('reservation_status_date' , inplace = True)
not_cancelled_data = df[df['is_canceled'] ==0]
not_cancelled_df_adr = not_cancelled_data.groupby('reservation_status_date')[['adr']].mean()
not_cancelled_df_adr.reset_index(inplace = True )
not_cancelled_df_adr.sort_values('reservation_status_date' , inplace = True )
plt.figure(figsize = (20,6))
plt.title('Average Daily Rate')
plt.plot(not_cancelled_df_adr['reservation_status_date'],not_cancelled_df_adr['adr'], label = 'not cancelled ')
plt.plot(cancelled_df_adr['reservation_status_date'],cancelled_df_adr['adr'], label = 'cancelled')
plt.legend()
# In[88]:
cancelled_df_adr = cancelled_df_adr[(cancelled_df_adr['reservation_status_date']>'2016')&(cancelled_df_adr['reservation_status_date']<'2017-09')]
not_cancelled_df_adr = not_cancelled_df_adr[(not_cancelled_df_adr['reservation_status_date']>'2016')&(not_cancelled_df_adr['reservation_status_date']<'2017-09')]
# In[91]:
plt.figure(figsize = (20,6))
plt.title('Average Daily Rate' , fontsize = 30)
plt.plot(not_cancelled_df_adr['reservation_status_date'],not_cancelled_df_adr['adr'], label = 'not cancelled ')
plt.plot(cancelled_df_adr['reservation_status_date'],cancelled_df_adr['adr'], label = 'cancelled')
plt.legend(fontsize = 20)
plt.show()
# In[ ]: