[Python] Visualize overseas Japanese soccer players on a map as of 2021.1.1

Japanese football players in foreign clubs shown on the map.

About this article

Currently, the trend of Villarreal Kubo is being talked about, but I tried to visualize where the players who are active overseas are in Python/Folium. I would like to explain the points that I devised in that.

    1. Made the icon a mark of your team in Folium
    1. Display by mouse over instead of clicking the player name
    1. Data acquisition / preprocessing


Please access the completed one here スクリーンショット 2021-01-08 210733.png スクリーンショット 2021-01-08 210857.png

About team icon display

The custom icon used folium.features.CustomIcon. There wasn't much explanation in Japanese, and I managed to do it by relying on Explanation of Folium's site in English.

The team icons are collected on the net, the background is transparent and png, and they are put in the image folder, and the error handling when the icon is not found is also included in the following code.

Display by mouse over instead of clicking the player name

Displaying information with this mouse over is called a tooltip in English. When you specify the Folium marker tooltip ='string' Just specify with. Please refer to the code below.

Data acquisition / preprocessing

First of all, based on the information on Wikipedia, the longitude / latitude, icons, etc. of the home town and home stadium are collected and made into Excel. I really wanted to do it automatically by scraping, but since there aren't many, I decided to do it manually. .. .. The collected data of each player/team is saved in EXCEL and plotted from Pandas/Dataframe.

Excel data is used only in this light blue column スクリーンショット 2021-01-04 103045.png

It was difficult to collect data as it was. Sweat


import pandas as pd
import folium
from glob import glob

df_player= pd.read_excel ('PlayerClubData.xlsx', header=0,encoding='utf-8' )

m = folium.Map(location=[46, -1.5],  zoom_start=4)

for club in df_player['club'].unique():
    df2=df_player[df_player['club']==club]  #If there are two or more people, combine the names
    names=' '.join(df2['Player'].tolist()) # Series = > List =>join and str

    for item in df2.head(1).iterrows():  #It's a little confusing, but since only the first person in each club is plotted, head(1)

        if item[1]['lat']>0 or item[1]['lat']<0 :  #Longitude data is float and nan is skipped
            l_in = [s for s in glob("./images/*.png ") if club in s]  #Check for icon files
            if len(l_in)>0: #Number of applicable files: Usually 1
                iconTmp = folium.features.CustomIcon(l_in[0], icon_size=(50,50)) #Specify the icon file here
                iconTmp=folium.Icon(color='red') #Click here if there is no icon file

            folium.Marker(location=[item[1]['lat'], item[1]['lon']], 
                tooltip=item[1]['club']+'<br>'+names,   #This tooltip can be displayed by mouse over
                icon=iconTmp).add_to(m) #Make it the icon file specified above

print ('finished!')

[Click here for source code and data files] (https://github.com/Kent747Tak/J-FootballPlayersAbroad)


Sample to display icon in Folium (English) Python Folium — A Data Visualization Superhero The sample code was easy to understand.

[Clubs of overseas soccer teams --Full screen map] (https://map.ultra-zone.net/japanese_player) At first, I saw this and wanted to make the same thing. Is this member 2012? !!

Visualize the location of hospitals in Iwate prefecture with Python folium I also referred to this in various ways.


I couldn't easily go abroad with covid-19, but personally, it's good to go around sightseeing spots when traveling abroad, but I think it's fun to watch soccer games locally. In that case, I would like you to consider a route that allows you to watch the game efficiently on this map.

Personally, I have high expectations for Takefusa Kubo, Takumi Minamino, Yukiya Sugita and Ryo Miyaichi in Sweden!

Recommended Posts

[Python] Visualize overseas Japanese soccer players on a map as of 2021.1.1
Folium: Visualize data on a map with Python
Visualize grib2 on a map with python (matplotlib)
Visualize prefectures with many routes by prefecture on a Japanese map
Map rent information on a map with python
[Python] Japanese localization of matplotlib on Ubuntu
A memo of a tutorial on running python on heroku
[Python] Plot data by prefecture on a map (number of cars owned nationwide)
(Python) Treat integer values as a set of flags
Visualize and understand Japan's regional mesh on a map
Visualize B League goals and goals on a heat map
Support for Python 2.7 runtime on AWS Lambda (as of 2020.1)
A memorandum of stumbling on my personal HEROKU & Python (Flask)
Memo of python + numpy/scipy/pandas/matplotlib/jupyterlab environment construction on M1 macOS (as of 2020/12/24)
A record of hell lessons imposed on beginner Python students
How to register a package on PyPI (as of September 2017)
[Python] Correct usage of map
Handling of python on mac
What is a python map?
Automation of a research on geographical information such as store network using Python and Web API
Save the result of the life game as a gif with python
[Python] I wrote the route of the typhoon on the map using folium
Format when passing a long string as an argument of python
I did a lot of research on how Python is executed
Get the number of readers of a treatise on Mendeley in Python
A record of patching a python package
Use pymol as a python library
A good description of Python decorators
Building a Python environment on Ubuntu
[Python] A memorandum of beautiful soup4
Create a Python environment on Mac (2017/4)
A brief summary of Python collections
Ideone> Python version: 3.5 (as of August 29, 2017)
Use blender as a python module
Create a python environment on centos
Environment construction of python3.8 on mac
Launch a Python script as a service
Register as a package on PyPI
Build a python3 environment on CentOS7
If you want a singleton in python, think of the module as a singleton
Run a batch of Python 2.7 with nohup on Amazon Linux AMI on EC2
[Python, ObsPy] I drew a beach ball on the map with Cartopy + ObsPy.