-
Notifications
You must be signed in to change notification settings - Fork 0
/
Projects_03_Valeeva.py
277 lines (99 loc) · 3.38 KB
/
Projects_03_Valeeva.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
272
273
274
275
276
#!/usr/bin/env python
# coding: utf-8
# ## Project Week 3 Valeeva
# ## Houses in emergency condition in Sverdlovsk region, Russia
# In[7]:
import pandas as pd
# In[9]:
df = pd.read_csv("Alarm_Sverd_Clean.csv")
# In[17]:
#df.head()
# ### Total number of houses in emergency condition in the region
# In[16]:
len(df.index)
# There is a total of 3398 houses in emergency condition in Sverdlovsk region, which is right in the middle of Russia. Houses in emergency condition are those that ...
# ### % of houses in the region that are in emergency condition
# In[19]:
round((len(df.index)/42210)*100)
# ### total number of people living in these conditions
# In[20]:
df.residents_count.sum()
# ### % of people in the region that live in emergency condition
# In[22]:
round(df.residents_count.sum()/4290067*100)
# In[25]:
df.info(verbose=True)
# In[28]:
df.determined_date.head()
# In[29]:
df.exploitation_start_year.head()
# In[32]:
#df.determined_date.str.split(pat="/")
# In[35]:
new = df.determined_date.str.split("/", n = 2, expand = True)
# In[37]:
new.head()
# In[39]:
df["determined_year"] = new[2]
# In[40]:
df.determined_year.head()
# In[46]:
df = df.dropna(subset=['determined_year'])
# In[47]:
df.determined_year = df.determined_year.astype(int)
# In[48]:
df['exploitation']=(df.determined_year-df.exploitation_start_year)
# ## On average, houses have been in use for 61 years before they are determined as emergency housing.
# In[52]:
df['exploitation'].median()
# ### there are, however, some outliers, such as the oldest house which is more than 200 years old...
# In[53]:
df['exploitation'].max()
# In[56]:
pd.set_option('display.max_columns', None)
# In[57]:
df.loc[df['exploitation'] == 204]
# ### or baby houses like this one which is just 1 year old but is already in emergency condition!
# In[54]:
df['exploitation'].min()
# In[ ]:
## Here is a distribution of the age of houses that are in emergency condition
# In[58]:
df['exploitation'].plot(kind='hist')
# ## As for the reason of the house being in emergency condition, it's mostly physical deterioration. However, fires are also a reason for 2% of the cases.
# In[59]:
df.alarm_reason.value_counts()
# In[60]:
round(df.alarm_reason.value_counts(normalize=True)*100)
# ## Resettlement
# In[61]:
df.planned_resettlement_date.head()
# In[62]:
df = df.dropna(subset=['planned_resettlement_date'])
# In[63]:
new = df.planned_resettlement_date.str.split("/", n = 2, expand = True)
# In[64]:
new.head()
# In[65]:
df["resettlement_year"] = new[2]
# In[67]:
df.resettlement_year.head()
# In[68]:
df.resettlement_year = df.resettlement_year.astype(int)
# In[69]:
df['wait_years']=(df.resettlement_year-df.determined_year)
# ## On average, people wait for the resettlement for 10 years
# In[70]:
df['wait_years'].median()
# In[74]:
#df.loc[df['alarm_reason'] == 'Пожар'].groupby(by="resettlement_year")
# In[86]:
df_fire = df[df['alarm_reason']=='Пожар']
# In[92]:
#ok so our of 29 houses that were on fire I only have 12 with the filled resettlement year
len(df_fire)
# In[ ]:
#we could use 0 as a replacement if this is not used throughout the dataset
# ## And there are at least 6 houses that have been on fire but still waiting to be resettled!
# In[99]:
len(df_fire[df_fire['resettlement_year']>2021])