Recently, I tried using folium, a library that displays data on a map, so I summarized it in an article while studying.
Folium is a python library that visualizes data with a map of Leaflet.js.
You can take advantage of both python data manipulation and leaflet mapping.
Github:https://github.com/python-visualization/folium Documentation:https://python-visualization.github.io/folium/
You can install it with pip install.
folium installation
$ pip install folium
First, use jupyter to display a map of Japan centered on Tokyo Station ([35.681167, 139.767052]).
If you enter latitude and longitude in location
, you can display a map centered on that position.
Plot a map of Japan centered around Tokyo Station
import folium
map_ = folium.Map(location=[35.681167, 139.767052], zoom_start=7)
map_
The map could be displayed with only 3 lines.
Next, let's map the location information of the department store to the created map of Japan. I searched the location information of the department store on HP and saved it as a csv file.
The csv file is saved in this format. (department_info.csv
)
store_name | contry | area | prefecture | city | address | latitude | longitude | depart | |
---|---|---|---|---|---|---|---|---|---|
0 | Nihombashi Mitsukoshi Main Store | Japan | Kanto | Tokyo | Chuo-ku | 1 Nihonbashi Muromachi, Chuo-ku, Tokyo-4-1 | 35.685633 | 139.773430 | Mitsukoshi |
1 | Ginza Mitsukoshi | Japan | Kanto | Tokyo | Chuo-ku | 4 Ginza, Chuo-ku, Tokyo-6-16 | 35.671370 | 139.765738 | Mitsukoshi |
・ ・ ・ | |||||||||
88 | ShinQs Beauty Palette Machida | Japan | Kanto | Tokyo | Machida City | 6 Haramachida, Machida-shi, Tokyo-4-1 Machida Tokyu Twins WEST 3F | 35.542690 | 139.446409 | Tokyu Department Store |
89 | Nagano Tokyu Department Store | Japan | Chubu | Nagano Prefecture | Nagano city | 1 Minamichitose, Nagano City, Nagano Prefecture-1-1 | 36.645052 | 138.188676 | Tokyu Department Store |
Add a department store marker to the map you just displayed
import pandas as pd
data = pd.read_csv('department_info.csv')
color_list = {'Mitsukoshi':'red', 'Daimaru':'blue', 'Seibu / Sogo':'green',
'Takashimaya':'purple', 'Hankyu Hanshin':'orange', 'Tokyu Department Store':'darkred'}
for k, v in data.iterrows():
folium.Marker([v.latitude, v.longitude], popup=v.store_name, icon=folium.Icon(color=color_list[v.depart])).add_to(map_)
map_
popup=xxx
If you add a comment to xxx, it can be displayed as a pop-up.
icon=folium.Icon(color=xxx1, icon=xxx2)
The marker icon type can be changed by specifying xxx1 and xxx2.
Colors that can be used for xxx1
[‘red’, ‘blue’, ‘green’, ‘purple’, ‘orange’, ‘darkred’,
’lightred’, ‘beige’, ‘darkblue’, ‘darkgreen’, ‘cadetblue’,
‘darkpurple’, ‘white’, ‘pink’, ‘lightblue’, ‘lightgreen’,
‘gray’, ‘black’, ‘lightgray’]
Markers that can be used for xxx2 https://glyphsearch.com/?library=font-awesome
Next, let's display a circle with a radius of 20km for each displayed department store.
20km area from the department store is displayed in yen
for k, v in data.iterrows():
folium.Circle([v.latitude, v.longitude], radius=20 * 1000, tooltip='20km', popup=v.store_name
, color=color_list[v.depart], fill_color=None).add_to(map_)
map_
I saved the last created map in html format.
Save the created map
map_.save('department_location.html')
I was able to visualize a beautiful map more easily than I expected.
(Reposted due to account migration)
Recommended Posts