-
Notifications
You must be signed in to change notification settings - Fork 0
/
column_tut.py
216 lines (160 loc) · 5.31 KB
/
column_tut.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
import pandas as pd
import numpy as np
import streamlit as st
import pydeck as pdk
st.title("Rental properties in New York City")
#df = pd.read_csv('https://raw.githubusercontent.com/muumrar/columns/main/nylatlonv2.csv', na_values= '#DIV/0!')
df = pd.read_csv('https://raw.githubusercontent.com/muumrar/columns/main/nylatlonv4.csv', na_values= '#DIV/0!')
df.info()
#df = pd.read_csv('https://raw.githubusercontent.com/muumrar/columns/main/nylatlon.csv', na_values= '#DIV/0!')
#df.replace(to_replace = np.nan, value = 1)
new_df = df.dropna(axis=0, how = 'any')
#new_df.info()
new_df = new_df[new_df["price"] < 10000]
new_df = new_df[new_df["price"] > 999]
new_df["solo_salary"] = new_df["price_per_bed"] / 0.025
new_df["unit_salary"] = new_df["price"] / 0.025
salary = 45000
new_df["afford"] = np.where(new_df["price_per_bed"] < (salary/12) * 0.3, "affordable", "not affordable")
#new_df.assign(new_df["affordability"]= "affordable".where(new_df.unit_salary < (salary/12) * 0.3, "not affordable"))
# if new_df["unit_salary"] < (salary/12) * 0.3:
# new_df["affordability"] = "affordable"
# else:
# new_df["affordability"] = "not affordable"
new_df.info()
#print(new_df.info())
#print(new_df.head())
crime_data = pd.read_csv('https://raw.githubusercontent.com/muumrar/columns/main/NYPD_Shooting_Incident_Data__Year_To_Date_Clean.csv')
crime_data.columns = crime_data.columns.str.lower()
crime_data = crime_data.rename(columns={'longitude': 'lon', 'latitude': 'lat'})
#crime_data.info()
tree_data = pd.read_csv('https://raw.githubusercontent.com/muumrar/columns/main/Forestry_Tree_Points_clean.csv')
#tree_data.info()
COLOR_BREWER_BLUE_SCALE = [
[0,100,0],
[34,139,34],
[50,205,50],
[152,251,152],
[0,250,154],
[32,178,170],
]
#cols = ["price_per_bed", "price_per_bed_scale"]
#bool_series = pd.isnull(df[cols])
#print(df[bool_series])
#cols = ["beds", "price_per_bed", "price_per_bed_scale"]
#df[cols] = df[cols].astype(int)
#df["price"] = df["price"].astype(float)
#print(df.head())
#df.dropna()
#print(df["price_per_bed"])
#df["price_per_bed"] = df["price_per_bed"].astype(float, errors = 'raise')
#df = pd.read_csv('https://raw.githubusercontent.com/muumrar/columns/main/nylatlonbasic.csv')
#df['price / bed'] = df['price']/df['beds']
#print(df.head())
number = st.number_input("Insert your yearly salary")
if number == 0:
salary = 0
else:
salary = number
show_afford = st.checkbox("show only those properties avaialble to your budget")
if show_afford:
new_df = new_df[new_df["afford"] == "affordable"]
if st.checkbox('Show raw data'):
st.subheader('Raw Data')
st.write(new_df)
#print(df.info())
#st.map(new_df)
#st.map(df)
#data = df.to_json(orient='table')
#print(data)
view = pdk.ViewState(
latitude=40.65,
longitude=-74.00,
zoom=10,
pitch=50,
)
column_layer = pdk.Layer(
"ColumnLayer",
data=new_df,
#data=crime_data,
get_position=["lon", "lat"],
get_elevation="price_per_bed_scale",
elevation_scale=5,
radius=100,
#get_fill_color=[255, 100, 255, 255],
#get_fill_color=["price_per_bed_scale ", "price_per_bed_scale / 8", "price_per_bed_scale", 255],
get_fill_color=["100 / distance_between ", "distance_between", "100 / distance_between", 140],
pickable=True,
auto_highlight=True,
)
tree_heat = pdk.Layer(
"HeatmapLayer",
data=tree_data,
#data=new_df,
opacity=0.9,
get_position=["lon", "lat"],
aggregation=pdk.types.String("MEAN"),
color_range=COLOR_BREWER_BLUE_SCALE,
threshold=1,
#get_weight="weight",
pickable=True,
)
crime_layer = pdk.Layer(
"ScatterplotLayer",
crime_data,
pickable=True,
opacity=0.8,
stroked=True,
filled=True,
radius_scale=5,
radius_min_pixels=1,
radius_max_pixels=100,
line_width_min_pixels=1,
get_position=["lon", "lat"],
get_radius=100,
get_fill_color=[255, 140, 0],
get_line_color=[0, 0, 0],
)
hex_layer = pdk.Layer(
"HexagonLayer",
crime_data,
get_position=["lon", "lat"],
auto_highlight=True,
elevation_scale=0,
pickable=True,
elevation_range=[0, 3000],
extruded=True,
coverage=1,
)
tooltip = {
"html": "<b>${price_per_bed}</b> per bed, location: {borough} (<b>{lat}, {lon}</b>), <br/> Nearest metro: <b>{nearest_station}</b>, {distance_between}km away",
"style": {"background": "grey", "color": "white", "font-family": '"Helvetica Neue", Arial', "z-index": "10000"},
}
r_prop = pdk.Deck(
#[column_layer, hex_layer],
column_layer,
initial_view_state=view,
tooltip=tooltip,
map_provider="mapbox",
map_style=pdk.map_styles.SATELLITE,
)
r_crime = pdk.Deck(
hex_layer,
initial_view_state=view,
tooltip=tooltip,
map_provider="mapbox",
map_style=pdk.map_styles.SATELLITE,
)
r_tree = pdk.Deck(
tree_heat,
initial_view_state=view,
map_provider="mapbox",
map_style=pdk.map_styles.SATELLITE
)
#st.map(r)
st.pydeck_chart(r_prop)
st.subheader('Police data on shootings in NYC in last year')
st.pydeck_chart(r_crime)
st.subheader('Tree coverage in the city')
#st.map(tree_data)
st.pydeck_chart(r_tree)