In my origin post, I was getting an error when trying to create my map but I think I managed to get passed that. I am sure I am not selecting the right key_on
feature but not sure why this won't display the right image. Please help! I got my file from here http://adamw523.com/toronto-geojson/
I am hoping to get something like this.
Here is what I am tried
df_crime=pd.DataFrame(df.Neighbourhood)
df_crime['premisetype']=pd.DataFrame(df.premisetype)
df_crime['offence']=pd.DataFrame(df.offence)
df_crime['MCI']=pd.DataFrame(df.MCI) #major crime indicators e.g. Theft
df_crime['occurrencedate']=pd.DataFrame(df.occurrencedate)
df_crime['reporteddate']=pd.DataFrame(df.reporteddate)
df_crime['occurrencehour'] = df_crime.occurrencedate.dt.strftime('%H:%M')
df_crime['reportedyear'] = df_crime.reporteddate.dt.strftime('%Y')
df_crime['reportedmonth'] = df_crime.reporteddate.dt.strftime('%m')
df_crime['reportedday'] = df_crime.reporteddate.dt.strftime('%d')
df_crime['reportedhour'] = df_crime.reporteddate.dt.strftime('%H:%M')
df_crime['Lat']=pd.DataFrame(df.Lat)
df_crime['Long']=pd.DataFrame(df.Long)
df_crime.head()
And the coordinates I am using are:
TORONTO_LAT = 43.70011 TORONTO_LONG = -79.4163
I also have this code to give me the counts
df_crime1=df_crime.groupby('Neighbourhood').size().reset_index(name="Count")
world_geo = r'simple.geojson' # geojson file
# create map of Toronto using latitude and longitude values
map_toronto = folium.Map(location=[TORONTO_LAT,TORONTO_LONG ], zoom_start=10)
folium.Choropleth(geo_data=world_geo,
data=df_crime1,
columns=['Neighbourhood', 'Count'],
key_on='feature.properties.DAUID',
fill_color='YlOrRd',
fill_opacity=0.7,
line_opacity=0.2,
legend_name='Crime Rate in Toronto'
).add_to(map_toronto)
map_toronto
Here is a the image I am getting
In my origin post, I was getting an error when trying to create my map but I think I managed to get passed that. I am sure I am not selecting the right key_on
feature but not sure why this won't display the right image. Please help! I got my file from here http://adamw523.com/toronto-geojson/
I am hoping to get something like this.
Here is what I am tried
df_crime=pd.DataFrame(df.Neighbourhood)
df_crime['premisetype']=pd.DataFrame(df.premisetype)
df_crime['offence']=pd.DataFrame(df.offence)
df_crime['MCI']=pd.DataFrame(df.MCI) #major crime indicators e.g. Theft
df_crime['occurrencedate']=pd.DataFrame(df.occurrencedate)
df_crime['reporteddate']=pd.DataFrame(df.reporteddate)
df_crime['occurrencehour'] = df_crime.occurrencedate.dt.strftime('%H:%M')
df_crime['reportedyear'] = df_crime.reporteddate.dt.strftime('%Y')
df_crime['reportedmonth'] = df_crime.reporteddate.dt.strftime('%m')
df_crime['reportedday'] = df_crime.reporteddate.dt.strftime('%d')
df_crime['reportedhour'] = df_crime.reporteddate.dt.strftime('%H:%M')
df_crime['Lat']=pd.DataFrame(df.Lat)
df_crime['Long']=pd.DataFrame(df.Long)
df_crime.head()
And the coordinates I am using are:
TORONTO_LAT = 43.70011 TORONTO_LONG = -79.4163
I also have this code to give me the counts
df_crime1=df_crime.groupby('Neighbourhood').size().reset_index(name="Count")
world_geo = r'simple.geojson' # geojson file
# create map of Toronto using latitude and longitude values
map_toronto = folium.Map(location=[TORONTO_LAT,TORONTO_LONG ], zoom_start=10)
folium.Choropleth(geo_data=world_geo,
data=df_crime1,
columns=['Neighbourhood', 'Count'],
key_on='feature.properties.DAUID',
fill_color='YlOrRd',
fill_opacity=0.7,
line_opacity=0.2,
legend_name='Crime Rate in Toronto'
).add_to(map_toronto)
map_toronto
Here is a the image I am getting
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.