Skip to content

Commit

Permalink
implementing changes to visualizations #1
Browse files Browse the repository at this point in the history
  • Loading branch information
robertcinca committed Feb 25, 2020
1 parent d0d3b32 commit 03e798f
Show file tree
Hide file tree
Showing 8 changed files with 825 additions and 553 deletions.
674 changes: 341 additions & 333 deletions Pipfile.lock

Large diffs are not rendered by default.

47 changes: 39 additions & 8 deletions fetch_new_builds/fetch_new_builds.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,37 @@
from lib_db.longlet_fund.models import PropertyHull
import pandas as pd

# pd.set_option('display.max_rows', 500)
# pd.set_option("display.max_columns", 500)
pd.set_option('display.max_rows', 500)
pd.set_option("display.max_columns", 500)
# pd.set_option('display.width', 1000)


class FetchNewBuild:
zoopla_historic_prop_type_mapping = {
"terraced house": "house",
"semi-detached house": "house",
"bungalow": "house",
"link-detached house": "house",
"detached house": "house",
"detached bungalow": "house",
"terraced bungalow": "house",
"end terrace house": "house",
"semi-detached bungalow": "house",
"town house": "house",
"cottage": "house",
"town house": "house",
"mews house": "house",
"houseboat": "house",
"country house": "house",
"barn conversion/farmhouse": "house",
"barn conversion": "house",
"house": "house",
"flat": "flat",
"maisonette": "flat",
"studio": "flat",
"block of flats": "flat",
}

def fetch_new_builds(self):
new_build_object = (
ZooplaSale.objects.select_related("zoopla", "zoopla__postcode")
Expand Down Expand Up @@ -38,39 +63,45 @@ def fetch_new_builds(self):
print()

new_build_df = pd.DataFrame.from_records(new_build_object.values()).fillna(0)
new_build_df["property_type"] = new_build_df.apply(lambda x: (self.zoopla_historic_prop_type_mapping[x.property_type] or None), axis=1)

print("Records: ")
print(new_build_df)
print()

# new_build_df.apply(lambda x: (self._fetch_matching_hulls(x) or {}), axis=1)

new_build_df["average_income"] = new_build_df.apply(lambda x: (self.fetch_matching_hulls(x) or {}).get("average_income") or 0, axis=1) #or 0
new_build_df.drop(new_build_df[new_build_df.average_income == 0].index, inplace=True)
new_build_df["yield"] = round(pd.to_numeric(new_build_df["average_income"]/new_build_df["price"]*100), 2)

new_build_df["postal_sector"] = new_build_df["postcode"].str[:-2]

print("Records with yield: ")
print(new_build_df)

new_build_df.to_csv("new_builds_in_hulls_with_yields.csv", sep=",", encoding="utf-8", index=False)

def fetch_matching_hulls(self, row):
# print(row)


def _fetch_matching_hulls(self, row):
record_filter = {
"geometry__intersects": row.point,
"bedrooms": row.bedrooms,
# "property_type": row.property_type,
}
return (
item = (
PropertyHull.objects
.prefetch_related("propertyhullstatistic_set")
.filter(**record_filter)

.filter(**record_filter)
.annotate(
average_income=F("propertyhullstatistic__average_income"),
)
.values("average_income")
.order_by("income_band")
.first()
)
print(item)
return item


if __name__ == "__main__":
Expand Down
213 changes: 2 additions & 211 deletions fetch_new_builds/new_builds_in_hulls_with_yields.csv

Large diffs are not rendered by default.

221 changes: 221 additions & 0 deletions property_count_per_city/cities_by_property_number.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
,city,count
65,East Cambridgeshire,1
47,Chichester,1
49,Chorley,1
183,Stroud,1
28,Bromsgrove,1
63,Dover,1
67,East Northamptonshire,1
201,Waverley,1
180,Stevenage,1
72,Eden,1
170,South Norfolk,1
171,South Northamptonshire,1
198,Walsall,1
127,Newcastle-under-Lyme,1
134,North West Leicestershire,1
124,New Forest,1
212,Windsor and Maidenhead,1
92,Harrogate,1
186,Sutton,2
182,Stratford-on-Avon,2
141,Oxford,2
155,Rushcliffe,2
156,Rushmoor,2
91,Harlow,2
161,Sevenoaks,2
34,Cambridge,2
88,Guildford,2
23,Breckland,2
75,Epping Forest,3
151,Rossendale,3
80,Forest of Dean,3
172,South Oxfordshire,3
94,Hart,3
169,South Lakeland,3
86,Great Yarmouth,3
71,Eastleigh,3
130,North Kesteven,3
206,West Oxfordshire,3
210,Wiltshire,3
14,Blaby,3
22,Braintree,3
203,Welwyn Hatfield,3
197,Vale of White Horse,4
207,West Suffolk,4
85,Gravesham,4
99,Hillingdon,4
140,Oadby and Wigston,4
192,Test Valley,4
193,Tewkesbury,4
104,Kettering,5
29,Broxbourne,5
147,Redditch,5
178,St Albans,5
41,Chelmsford,5
202,Wellingborough,5
68,East Riding of Yorkshire,5
121,Mid Sussex,5
163,Slough,5
215,Wokingham,5
179,St. Helens,5
185,Surrey Heath,5
181,Stockport,6
154,Runnymede,6
51,Corby,6
123,Mole Valley,6
76,Epsom and Ewell,6
48,Chiltern,7
31,Burnley,7
59,Daventry,7
43,Cherwell,7
33,Calderdale,7
39,Central Bedfordshire,8
167,South Holland,8
173,South Ribble,8
125,Newark and Sherwood,8
17,Bolsover,9
96,Havant,9
10,Bath and North East Somerset,9
211,Winchester,9
187,Swale,9
98,"Herefordshire, County of",9
46,Chesterfield,9
157,Rutland,9
27,Bromley,9
149,Ribble Valley,10
190,Tameside,10
8,Basingstoke and Deane,10
40,Charnwood,10
55,Croydon,10
129,North Hertfordshire,11
66,East Hertfordshire,11
200,Warwick,11
204,West Berkshire,11
148,Reigate and Banstead,11
20,Bracknell Forest,12
100,Hinckley and Bosworth,12
101,Huntingdonshire,12
6,Barnsley,13
106,Kingston upon Thames,13
69,East Staffordshire,13
58,Dartford,13
189,Swindon,14
164,Solihull,14
1,Arun,14
116,Maidstone,14
113,Lincoln,14
18,Bolton,15
90,Haringey,15
196,Trafford,16
97,Havering,16
12,Bexley,16
62,Dorset,16
7,Barrow-in-Furness,17
194,Thanet,17
209,Wigan,17
166,South Gloucestershire,17
52,Cornwall,17
38,Carlisle,18
30,Broxtowe,19
119,Medway,19
153,Rugby,19
132,North Somerset,20
219,Wyre Forest,20
208,Westminster,21
165,South Derbyshire,21
73,Elmbridge,22
214,Woking,22
199,Waltham Forest,22
146,Redbridge,23
107,Kirklees,24
174,South Somerset,25
109,Lancaster,25
105,"Kingston upon Hull, City of",25
102,Ipswich,25
77,Erewash,26
2,Ashfield,27
11,Bedford,27
84,Gosport,27
3,Aylesbury Vale,28
56,Dacorum,30
83,Gloucester,31
93,Harrow,33
216,Worthing,33
145,Reading,35
120,Merton,36
78,Exeter,37
0,Amber Valley,38
74,Enfield,38
191,Tendring,38
205,West Lindsey,38
15,Blackburn with Darwen,38
131,North Lincolnshire,39
79,Fenland,39
150,Rochdale,41
152,Rotherham,41
168,South Kesteven,41
217,Wycombe,41
177,Southwark,42
128,Newham,42
218,Wyre,42
42,Cheltenham,44
5,Barnet,44
25,Brighton and Hove,44
139,Nuneaton and Bedworth,45
184,Sunderland,45
103,Islington,46
142,Peterborough,47
32,Bury,50
24,Brent,53
4,Barking and Dagenham,54
95,Hastings,55
36,Canterbury,55
35,Camden,56
64,Dudley,57
82,Gedling,59
19,"Bournemouth, Christchurch and Poole",65
135,Northampton,67
115,Luton,72
50,Colchester,75
89,Hackney,75
112,Lewisham,76
87,Greenwich,77
9,Bassetlaw,80
45,Cheshire West and Chester,83
108,Knowsley,87
136,Northumberland,88
137,Norwich,99
122,Milton Keynes,100
159,Sandwell,118
176,Southampton,119
53,County Durham,122
70,East Suffolk,122
195,Tower Hamlets,126
81,Gateshead,136
118,Mansfield,141
175,South Tyneside,147
57,Darlington,149
160,Sefton,173
54,Coventry,189
144,Portsmouth,192
126,Newcastle upon Tyne,200
158,Salford,202
61,Doncaster,217
213,Wirral,220
133,North Tyneside,222
111,Leicester,230
44,Cheshire East,233
37,Cardiff,268
162,Sheffield,269
21,Bradford,280
188,Swansea,299
16,Blackpool,337
60,Derby,366
143,Plymouth,458
26,"Bristol, City of",597
110,Leeds,670
117,Manchester,692
114,Liverpool,975
138,Nottingham,992
13,Birmingham,1402
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

df.groupby(["city"])["city"].count().reset_index(name="count").sort_values(
"count"
).tail(5).to_csv("top_five_cities_by_property_number.csv", sep=",", encoding="utf-8")
).to_csv("cities_by_property_number.csv", sep=",", encoding="utf-8")
Loading

0 comments on commit 03e798f

Please sign in to comment.