Location information that has many opportunities to play an active role, such as checking the flow of people when planning to open a store. With the spread of SNS and IoT devices, I think there will be more and more opportunities to utilize location information for analysis.
This time, I had the opportunity to recently plot location information on a map and visualize it. When I looked it up, it seems that it can be visualized really easily with python.
This time I tried the following using the census data.
-** Map display on Jupyter Notebook ** -** Location information plot ** -** Creating a heat map **
-** folium.Map (params) : Create a map. - folium.Popup (params) : Display a popup. - folium.Marker (params) : Plot pins on the map. - folium.plugins.HeatMap (params) **: Create a layer for heatmap display.
● First, import the library.
import pandas as pd
import folium
● Load the dataset created in advance.
df = pd.read_csv('my_data.csv', encoding='shift_jis')
df.head(10)
It's a dataset like this.
● The basic use of folium, ・ Map display ・ Plot of location information ・ Display of pop-up I will try.
#Map object creation
map = folium.Map(location=[35.710402, 139.810668], zoom_start=18)
#Create pop-up(「show=Always displayed as "True")
p_up = folium.Popup('Tokyo Sky Tree', min_width=0, max_width=1000, show=True)
#Plot on a map object
folium.Marker(location=[35.710402, 139.810668], popup=p_up).add_to(map)
#Map display
map
● Finally, let's display the heat map. Import the plugin for heatmap display.
from folium.plugins import HeatMap
● The heat map can be displayed by passing latitude / longitude information as an argument. Adjust the radius and blur of each point to make it look a little better.
#Map object creation
map = folium.Map(location=[35.710402, 139.810668], zoom_start=5)
#Add heatmap layer to map object
HeatMap(df[['latitude', 'longitude']], radius=5, blur=5).add_to(map)
#Map display
map
● Currently, the data is meaningless just because the places with a large number of records and high density are red, so let's weight it with "H22-H27 population increase / decrease".
#Map object creation
map = folium.Map(location=[35.710402, 139.810668], zoom_start=5)
#Add heatmap layer to map object by adding population increase / decrease as an argument
HeatMap(df[['latitude', 'longitude', 'Number of population changes from 2010 to 2015 [People]']], radius=5, blur=5).add_to(map)
#Map display
map
The redness of areas with a large number of population changes has become stronger.
how was it? Do you have an image of handling location information data?
Bicycle rental companies analyze the user's riding distance and riding form to make a decision to enter the motorcycle rental business, and the government analyzes the flow line at the time of the event to secure the evacuation guidance route. It is a wide range of data.
I hope you will try it out!
Recommended Posts