I tried using folium

Introduction

Recently, I tried using folium, a library that displays data on a map, so I summarized it in an article while studying.

What is folium

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/

Installation

You can install it with pip install.

folium installation


$ pip install folium

Let's display the map!

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_
スクリーンショット 2019-12-03 14.31.51.png

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_
スクリーンショット 2019-12-03 15.13.48.png

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_
スクリーンショット 2019-12-03 16.34.28.png

I saved the last created map in html format.

Save the created map


map_.save('department_location.html')

in conclusion

I was able to visualize a beautiful map more easily than I expected.

(Reposted due to account migration)

Recommended Posts

I tried using folium
I tried using folium
I tried using argparse
I tried using anytree
I tried using aiomysql
I tried using Summpy
I tried using coturn
I tried using "Anvil".
I tried using Hubot
I tried using ESPCN
I tried using PyCaret
I tried using cron
I tried using ngrok
I tried using face_recognition
I tried using Jupyter
I tried using PyCaret
I tried using Heapq
I tried using doctest
I tried using jinja2
I tried using time-window
[I tried using Pythonista 3] Introduction
I tried using easydict (memo).
I tried face recognition using Face ++
I tried using Random Forest
I tried using BigQuery ML
I tried using Amazon Glacier
I tried using git inspector
[Python] I tried using OpenPose
I tried using magenta / TensorFlow
I tried using AWS Chalice
I tried using Slack emojinator
I tried using Rotrics Dex Arm # 2
I tried using Rotrics Dex Arm
I tried using GrabCut of OpenCV
I tried using Thonny (Python / IDE)
I tried server-client communication using tmux
I tried reinforcement learning using PyBrain
I tried deep learning using Theano
Somehow I tried using jupyter notebook
[Kaggle] I tried undersampling using imbalanced-learn
I tried shooting Kamehameha using OpenPose
I tried using the checkio API
[Python] I tried using YOLO v3
I tried asynchronous processing using asyncio
I tried PyQ
I tried AutoKeras
I tried papermill
I tried django-slack
I tried Django
I tried spleeter
I tried cgo
I tried using Amazon SQS with django-celery
I tried using Azure Speech to Text.
I tried using Twitter api and Line api
I tried playing a ○ ✕ game using TensorFlow
I tried using YOUTUBE Data API V3
I tried using Selenium with Headless chrome
I tried drawing a line using turtle
[Kaggle] I tried ensemble learning using LightGBM
I tried using PyEZ and JSNAPy. Part 2: I tried using PyEZ
I tried using Bayesian Optimization in Python