Skip to content

Instantly share code, notes, and snippets.

@zhonglism
Last active April 23, 2017 02:21
Show Gist options
  • Save zhonglism/77f8065920fec66862bbd738c269d0be to your computer and use it in GitHub Desktop.
Save zhonglism/77f8065920fec66862bbd738c269d0be to your computer and use it in GitHub Desktop.
Rental price data on map
# coding: utf-8
# In[31]:
import gmplot
import folium
import pandas as pd
# In[81]:
# rent['latitude'][1:5]
# gmap = gmplot.GoogleMapPlotter(40, -70, 12)
# # gmap.scatter([37.32],[21.33],'k',size=40,marker=True)
# # gmap.draw
# # gmap = gmplot.GoogleMapPlotter(37.428, -122.145, 16)
# gmap.scatter(rent['latitude'],rent['longitude'])
# gmap.draw('test.html')
# In[32]:
rent=pd.read_json('train.json')
# In[36]:
# rent.head(4)
rent.columns
# In[132]:
# map_1 = folium.Map(location=[45.372, -121.6972], zoom_start=12,tiles='Stamen Terrain')
# folium.Marker([45.3288, -121.6625], popup='Mt. Hood Meadows',
# icon = folium.Icon(icon = 'cloud')).add_to(map_1)
# folium.Marker([45.3311, -121.7113], popup='Timberline Lodge',
# icon = folium.Icon(color ='green')).add_to(map_1)
# folium.Marker([45.3300, -121.6823], popup='Some Other Location',
# icon = folium.Icon(color ='red')).add_to(map_1)
# map_1.save('iconTest.html')
# In[133]:
# map_1 = folium.Map(location=[45.372, -121.6972], zoom_start=12,tiles='Stamen Terrain')
# folium.Marker([[45.3288,45.3311],[-121.6635,-121.7113]]).add_to(map_1)
# map_1.save('iconTest.html')
# In[91]:
rent_min=rent[['latitude','longitude','price']].head(100)
rent_min.price.describe()
# rent_min['partition']=pd.qcut(rent_min.price,7,labels=['level'+str(i) for i in range(1,8)])
rent_min['partition']=pd.qcut(rent_min.price,7)
colormap={'[1300, 1907.143]':'#ffb3b3','(1907.143, 2363.143]':'#ff9999','(2363.143, 2968.143]':'#ff8080',
'(2968.143, 3328.571]':'#ff6666','(3328.571, 3952.143]':'#ff4d4d','(3952.143, 5599.286]':'#ff3333',
'(5599.286, 15000]':'#ff1a1a'}
partition=rent_min['partition'].tolist()
# for ele in b:
# print(ele)
colors=[]
for ele in partition:
colors.append(colormap[ele])
# a=pd.Series(a)
rent_min['color']=pd.Series(a,index=rent_min.index)
# In[130]:
map = folium.Map(location=[40.71, -74], zoom_start=10)
for i in range(rent_min.shape[0]):
folium.CircleMarker([rent_min.iloc[i,0],rent_min.iloc[i,1]],radius=5,
fill_color=rent_min.iloc[i,4],color=rent_min.iloc[i,4],
popup='Price '+str(rent_min.iloc[i,2])+'\nPartition is'+rent_min.iloc[i,3]).add_to(map)
map.save('test.html')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment