-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathData_Analysis.py
More file actions
325 lines (151 loc) · 4.93 KB
/
Data_Analysis.py
File metadata and controls
325 lines (151 loc) · 4.93 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
315
316
317
318
319
320
321
322
323
324
#!/usr/bin/env python
# coding: utf-8
# # Importing all the required libraries
# In[1]:
import numpy as np
import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
get_ipython().run_line_magic('matplotlib', 'inline')
matplotlib.rcParams["figure.figsize"] = (20,10)
import plotly.express as px
import seaborn as sns
# # Reading the data
# In[2]:
df = pd.read_csv('data_sets/prop_data_clean.csv')
# In[3]:
df.head(3)
# # Getting the shape of the data
# In[4]:
df.shape
# # Checking for null columns
# In[5]:
df.isnull().sum()
# In[6]:
df1 = df.copy()
# # Removing all the unwanted columns
# In[7]:
df1 = df.drop(['city', 'desc', 'floor_count', 'floor_num', 'id', 'id_string', 'latitude', 'longitude', 'poster_name', 'project', 'title', 'trans', 'url'], axis='columns')
df1.head()
# # Removing all the null values from the table
# In[8]:
df1.isnull().sum()
# In[9]:
df2 = df1.copy()
# In[10]:
df2 = df1.dropna()
df2.isnull().sum()
# In[11]:
df2.shape
# # Verifying the table
# In[12]:
df2.head()
# #### Creating columns for 'year date' and 'month' from the post_date column
# In[13]:
df2['year_posted'] = df2['post_date'].apply(lambda x: x.split('-')[0])
# In[14]:
df2['month_posted'] = df2['post_date'].apply(lambda x: x.split('-')[1])
# In[15]:
df2.head(5)
# # Deleting the post date column
# In[16]:
df2.drop(['post_date'], axis='columns')
# # Describing the table to know mean, sd
# In[17]:
df2.describe()
# # Removing outliers
# In[18]:
Q1 = df2.price.quantile(0.25)
Q3 = df2.price.quantile(0.75)
Q1, Q3
# In[19]:
IQR = Q3 - Q1
IQR
# In[20]:
lower_limit = Q1 - 1.5*(IQR)
upper_limit = Q1 + 1.5*(IQR)
lower_limit, upper_limit
# In[21]:
df3 = df2[(df2.price>lower_limit)&(df2.price<upper_limit)]
# # Histogram for area
# In[22]:
df3.area.hist()
# # Making box plot for the price column
# In[23]:
df3.boxplot(column='price')
plt.show()
# # Distribution plot for price
# In[24]:
sns.distplot(df3['price'])
# # Counter Plot for Total Number of User_Type
#
# From the below counter plot, It was found that Agent highest number and acts as a middle person for renting houses.
# In[25]:
sns.countplot(x='user_type', data=df3)
# ## Count plot for Number of houses posted for the past 2 years
#
# The Year 2020 has the highest number of houses for rent with count above 8000.
# In[26]:
sns.countplot(x='year_posted', data=df3)
# # Joint plot to display relationship between two variable Area and Price
# In[27]:
sns.jointplot(x='area', y='price', data=df3, kind='reg')
# # Pair plot to get the pair wise relationship from the dataset.
# In[28]:
sns.pairplot(df3, hue='user_type')
# # Creating a heatmap to find the correlation between variables
# In[29]:
sns.heatmap(df3.corr(), annot=True)
# # Creating Bar Graph for localities with total prices
#
# Credit/Resource: https://www.kaggle.com/shreekant009/mumbai-house-price-with-plotly
# In[30]:
mumbai = df3.groupby(['locality','price'])['area'].sum().reset_index().sort_values('price',ascending =False)
fig = px.bar(df3[:700], y='area', x='locality', color='price', height=600)
fig.update_layout(
title='Houses For Rent In Mumbai')
fig.show()
# # Treemap for the listed properties for Rent
#
# Credit/Resource: https://www.kaggle.com/shreekant009/mumbai-house-price-with-plotly
# In[31]:
df3['price'] = df3['price'].astype(float)
df3['bedroom_num'] = df3['bedroom_num'].astype(float)
fig = px.treemap(df3, path=['locality','area','price','bedroom_num'], color='locality')
fig.update_layout(
title='Properties For Rent')
fig.show()
# # Bar Chart for House for Rent
#
# Credit/Resource: https://www.kaggle.com/shreekant009/mumbai-house-price-with-plotly
# In[32]:
rent = df3.sort_values('price',ascending=False).head(100)
fig = px.bar(rent, x='locality', y='price', color='price', height=500, hover_data=['price','area','bedroom_num'])
fig.update_layout(
title='Houses For Rent')
fig.show()
# # Box Plot for Number of Bedroom
#
# Credit/Resource: https://www.kaggle.com/shreekant009/mumbai-house-price-with-plotly
# In[33]:
fig = px.box(df3, x="bedroom_num", y="price")
fig.update_layout(
title='Bedroom Wise House Price Rents')
fig.show()
# # Scatter Plot
#
# Credit/Resource: https://www.youtube.com/watch?v=cbqZa_1vzcg&list=PLeo1K3hjS3uu7clOTtwsp94PcHbzqpAdg&index=5&t=0s
# In[34]:
def scatter_chart(df,locality):
bhk2 = df3[(df3.locality==locality) & (df3.bedroom_num==2)]
bhk3 = df3[(df3.locality==locality) & (df3.bedroom_num==3)]
matplotlib.rcParams['figure.figsize'] = (15,10)
plt.scatter(bhk2.area,bhk2.price,color='blue',label='2 BHK', s=50)
plt.scatter(bhk3.area,bhk3.price,marker='+', color='green',label='3 BHK', s=50)
plt.xlabel("Total Area")
plt.ylabel("Price Per Thousand Indian Rupees")
plt.title(locality)
plt.legend()
scatter_chart(df3,"Andheri East")
# In[35]:
cleaned_data = df3.to_csv('data_sets/cleaned_data.csv', index=False)