In [1]:
from IPython.display import HTML
import requests
HTML(requests.get("https://git.io/fh5WI").text)
Out[1]:

Python and Jupyter for Programmers

Part 4: Analyzing Data with Pandas

go top

1. Working with Pandas DataFrames

 

Pandas is one of the most popular Python libraries used for data analysis.

In [2]:
import pandas as pd
Here is a link to a csv file with data about airports around the world:

https://git.io/fhdpp

Read a csv file with airport data:

In [3]:
df = pd.read_csv("https://git.io/fhdpp")
df
Out[3]:
id ident type name latitude_deg longitude_deg elevation_ft continent iso_country iso_region municipality scheduled_service gps_code iata_code local_code home_link wikipedia_link keywords
0 6523 00A heliport Total Rf Heliport 40.070801 -74.933601 11.0 NaN US US-PA Bensalem no 00A NaN 00A NaN NaN NaN
1 323361 00AA small_airport Aero B Ranch Airport 38.704022 -101.473911 3435.0 NaN US US-KS Leoti no 00AA NaN 00AA NaN NaN NaN
2 6524 00AK small_airport Lowell Field 59.949200 -151.695999 450.0 NaN US US-AK Anchor Point no 00AK NaN 00AK NaN NaN NaN
3 6525 00AL small_airport Epps Airpark 34.864799 -86.770302 820.0 NaN US US-AL Harvest no 00AL NaN 00AL NaN NaN NaN
4 6526 00AR closed Newport Hospital & Clinic Heliport 35.608700 -91.254898 237.0 NaN US US-AR Newport no NaN NaN NaN NaN NaN 00AR
5 322127 00AS small_airport Fulton Airport 34.942803 -97.818019 1100.0 NaN US US-OK Alex no 00AS NaN 00AS NaN NaN NaN
6 6527 00AZ small_airport Cordes Airport 34.305599 -112.165001 3810.0 NaN US US-AZ Cordes no 00AZ NaN 00AZ NaN NaN NaN
7 6528 00CA small_airport Goldstone /Gts/ Airport 35.350498 -116.888000 3038.0 NaN US US-CA Barstow no 00CA NaN 00CA NaN NaN NaN
8 324424 00CL small_airport Williams Ag Airport 39.427188 -121.763427 87.0 NaN US US-CA Biggs no 00CL NaN 00CL NaN NaN NaN
9 322658 00CN heliport Kitchen Creek Helibase Heliport 32.727374 -116.459742 3350.0 NaN US US-CA Pine Valley no 00CN NaN 00CN NaN NaN NaN
10 6529 00CO closed Cass Field 40.622202 -104.344002 4830.0 NaN US US-CO Briggsdale no NaN NaN NaN NaN NaN 00CO
11 6531 00FA small_airport Grass Patch Airport 28.645500 -82.219002 53.0 NaN US US-FL Bushnell no 00FA NaN 00FA NaN NaN NaN
12 6532 00FD heliport Ringhaver Heliport 28.846600 -82.345398 25.0 NaN US US-FL Riverview no 00FD NaN 00FD NaN NaN NaN
13 6533 00FL small_airport River Oak Airport 27.230900 -80.969200 35.0 NaN US US-FL Okeechobee no 00FL NaN 00FL NaN NaN NaN
14 6534 00GA small_airport Lt World Airport 33.767502 -84.068298 700.0 NaN US US-GA Lithonia no 00GA NaN 00GA NaN NaN NaN
15 6535 00GE heliport Caffrey Heliport 33.884201 -84.733902 957.0 NaN US US-GA Hiram no 00GE NaN 00GE NaN NaN NaN
16 6536 00HI heliport Kaupulehu Heliport 19.832715 -155.980233 43.0 NaN US US-HI Kailua/Kona no 00HI NaN 00HI NaN NaN NaN
17 6537 00ID small_airport Delta Shores Airport 48.145302 -116.213997 2064.0 NaN US US-ID Clark Fork no 00ID NaN 00ID NaN NaN NaN
18 322581 00IG small_airport Goltl Airport 39.724028 -101.395994 3359.0 NaN US US-KS McDonald no 00IG NaN 00IG NaN NaN NaN
19 6538 00II heliport Bailey Generation Station Heliport 41.644501 -87.122803 600.0 NaN US US-IN Chesterton no 00II NaN 00II NaN NaN NaN
20 6539 00IL small_airport Hammer Airport 41.978401 -89.560402 840.0 NaN US US-IL Polo no 00IL NaN 00IL NaN NaN NaN
21 6540 00IN heliport St Mary Medical Center Heliport 41.511398 -87.260597 634.0 NaN US US-IN Hobart no 00IN NaN 00IN NaN NaN NaN
22 6541 00IS small_airport Hayenga's Cant Find Farms Airport 40.025600 -89.122902 820.0 NaN US US-IL Kings no 00IS NaN 00IS NaN NaN NaN
23 6542 00KS small_airport Hayden Farm Airport 38.727798 -94.930496 1100.0 NaN US US-KS Gardner no 00KS NaN 00KS NaN NaN NaN
24 6543 00KY small_airport Robbins Roost Airport 37.409401 -84.619698 1265.0 NaN US US-KY Stanford no 00KY NaN 00KY NaN NaN NaN
25 45437 00LA heliport Shell Chemical East Site Heliport 30.191944 -90.980833 15.0 NaN US US-LA Gonzales no 00LA NaN 00LA NaN NaN NaN
26 6544 00LL heliport Ac & R Components Heliport 39.665298 -89.705597 600.0 NaN US US-IL Chatham no 00LL NaN 00LL NaN NaN NaN
27 6545 00LS small_airport Lejeune Airport 30.136299 -92.429398 12.0 NaN US US-LA Esterwood no 00LS NaN 00LS NaN NaN NaN
28 6546 00MD small_airport Slater Field 38.757099 -75.753799 45.0 NaN US US-MD Federalsburg no 00MD NaN 00MD NaN NaN NaN
29 6547 00MI heliport Dow Chemical Heliport 43.949402 -86.416702 588.0 NaN US US-MI Ludington no 00MI NaN 00MI NaN NaN NaN
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
55003 30646 ZYAS medium_airport Anshan Air Base 41.105301 122.853996 NaN AS CN CN-21 Anshan yes ZYAS AOG NaN NaN https://en.wikipedia.org/wiki/Anshan_Teng%27ao... NaN
55004 27237 ZYCC medium_airport Longjia Airport 43.996201 125.684998 706.0 AS CN CN-22 Changchun yes ZYCC CGQ NaN NaN http://en.wikipedia.org/wiki/Changchun_Longjia... NaN
55005 300858 ZYCH medium_airport Changhai Airport 39.266667 122.666944 80.0 AS CN CN-21 Changhai no ZYCH CNI NaN NaN http://en.wikipedia.org/wiki/Changhai_Airport NaN
55006 30827 ZYCY medium_airport Chaoyang Airport 41.538101 120.434998 568.0 AS CN CN-21 Chaoyang yes ZYCY CHG NaN NaN https://en.wikipedia.org/wiki/Chaoyang_Airport NaN
55007 327349 ZYDU medium_airport Wudalianchi Dedu Airport 48.445000 126.133000 984.0 AS CN CN-23 Wudalianchi yes ZYDU DTU NaN NaN https://en.wikipedia.org/wiki/Wudalianchi_Dedu... NaN
55008 324338 ZYFX small_airport Fuxin Airport 42.069014 121.718122 548.0 AS CN CN-21 Fuxin no ZYFX NaN NaN NaN NaN NaN
55009 313994 ZYFY medium_airport Dongji Aiport 48.199494 134.366447 NaN AS CN CN-23 Fuyuan yes ZYFY FYJ NaN NaN https://en.wikipedia.org/wiki/Fuyuan_Dongji_Ai... NaN
55010 27238 ZYHB large_airport Taiping Airport 45.623402 126.250000 457.0 AS CN CN-23 Harbin yes ZYHB HRB NaN NaN http://en.wikipedia.org/wiki/Harbin_Taiping_In... NaN
55011 31576 ZYHE medium_airport Heihe Airport 50.171621 127.308884 8530.0 AS CN CN-23 Heihe yes ZYHE HEK NaN NaN http://en.wikipedia.org/wiki/Heihe_Airport NaN
55012 31701 ZYJL small_airport Jilin Airport 44.002201 126.396004 NaN AS CN CN-22 Jilin no ZYJL JIL NaN NaN https://en.wikipedia.org/wiki/Jilin_Ertaizi_Ai... NaN
55013 27239 ZYJM medium_airport Jiamusi Airport 46.843399 130.464996 262.0 AS CN CN-23 Jiamusi yes ZYJM JMU NaN NaN http://en.wikipedia.org/wiki/Jiamusi_Airport NaN
55014 327450 ZYJS medium_airport Jiansanjiang Airport 47.110000 132.660278 NaN AS CN CN-23 Jiansanjiang yes ZYJS JSJ NaN NaN https://en.wikipedia.org/wiki/Jiansanjiang_Air... NaN
55015 313337 ZYJX medium_airport Jixi Xingkaihu Airport 45.293000 131.193000 760.0 AS CN CN-23 Jixi yes ZYJX JXA NaN NaN http://en.wikipedia.org/wiki/Jixi_Xingkaihu_Ai... NaN
55016 31706 ZYJZ medium_airport Jinzhou Airport 41.101398 121.061997 NaN AS CN CN-21 Jinzhou yes ZYJZ JNZ NaN NaN http://en.wikipedia.org/wiki/Jinzhou_Airport Xiaolingzi Air Base
55017 307012 ZYLD medium_airport Lindu Airport 47.752056 129.019125 791.0 AS CN CN-23 Yichun yes ZYLD LDS NaN NaN http://en.wikipedia.org/wiki/Yichun_Lindu_Airport Yichun Shi Airport
55018 300516 ZYLS medium_airport Yushu Batang Airport 32.836389 97.036389 12816.0 AS CN CN-63 Yushu no ZYLS YUS NaN NaN http://en.wikipedia.org/wiki/Yushu_Batang_Airport NaN
55019 27240 ZYMD medium_airport Mudanjiang Hailang International Airport 44.524101 129.569000 883.0 AS CN CN-23 Mudanjiang yes ZYMD MDG NaN NaN http://en.wikipedia.org/wiki/Mudanjiang_Airport Mudanjiang
55020 301193 ZYMH medium_airport Gu-Lian Airport 52.912778 122.430000 1836.0 AS CN CN-23 Mohe yes ZYMH OHE NaN NaN http://en.wikipedia.org/wiki/Mohe_Gulian_Airport NaN
55021 27241 ZYQQ medium_airport Qiqihar Sanjiazi Airport 47.239601 123.917999 477.0 AS CN CN-23 Qiqihar yes ZYQQ NDG NaN NaN http://en.wikipedia.org/wiki/Qiqihar_Airport NaN
55022 327451 ZYSQ medium_airport Songyuan Chaganhu Airport 44.938114 124.550178 459.0 AS CN CN-22 Qian Gorlos Mongol Autonomous County yes ZYSQ YSQ NaN NaN https://en.wikipedia.org/wiki/Songyuan_Chaganh... NaN
55023 307017 ZYTH small_airport Tahe Airport 52.224444 124.720222 1240.0 AS CN CN-23 Tahe no ZYTH NaN NaN NaN NaN NaN
55024 27242 ZYTL large_airport Zhoushuizi Airport 38.965698 121.539001 107.0 AS CN CN-21 Dalian yes ZYTL DLC NaN NaN http://en.wikipedia.org/wiki/Dalian_Zhoushuizi... Dalian Air Base
55025 307013 ZYTN medium_airport Tonghua Sanyuanpu Airport 42.253889 125.703333 1200.0 AS CN CN-22 Tonghua yes ZYTN TNH NaN NaN http://en.wikipedia.org/wiki/Tonghua_Sanyuanpu... Tonghua Liuhe Airport
55026 27243 ZYTX large_airport Taoxian Airport 41.639801 123.483002 198.0 AS CN CN-21 Shenyang yes ZYTX SHE NaN NaN http://en.wikipedia.org/wiki/Shenyang_Taoxian_... NaN
55027 27244 ZYYJ medium_airport Yanji Chaoyangchuan Airport 42.882801 129.451004 624.0 AS CN CN-22 Yanji yes ZYYJ YNJ NaN NaN http://en.wikipedia.org/wiki/Yanji_Chaoyangchu... NaN
55028 317861 ZYYK medium_airport Yingkou Lanqi Airport 40.542524 122.358600 0.0 AS CN CN-21 Yingkou yes ZYYK YKH NaN NaN https://en.wikipedia.org/wiki/Yingkou_Lanqi_Ai... NaN
55029 32753 ZYYY medium_airport Shenyang Dongta Airport 41.784401 123.496002 NaN AS CN CN-21 Shenyang no ZYYY NaN NaN NaN NaN NaN
55030 46378 ZZ-0001 heliport Sealand Helipad 51.894444 1.482500 40.0 EU GB GB-ENG Sealand no NaN NaN NaN http://www.sealandgov.org/ http://en.wikipedia.org/wiki/Principality_of_S... Roughs Tower Helipad
55031 307326 ZZ-0002 small_airport Glorioso Islands Airstrip -11.584278 47.296389 11.0 AF TF TF-U-A Grande Glorieuse no NaN NaN NaN NaN NaN NaN
55032 313629 ZZZZ small_airport Satsuma Iōjima Airport 30.784722 130.270556 338.0 AS JP JP-46 Mishima-Mura no RJX7 NaN NaN NaN http://wikimapia.org/6705190/Satsuma-Iwo-jima-... SATSUMA,IWOJIMA,RJX7

55033 rows × 18 columns

Select a column:
In [4]:
df['elevation_ft']
Out[4]:
0           11.0
1         3435.0
2          450.0
3          820.0
4          237.0
5         1100.0
6         3810.0
7         3038.0
8           87.0
9         3350.0
10        4830.0
11          53.0
12          25.0
13          35.0
14         700.0
15         957.0
16          43.0
17        2064.0
18        3359.0
19         600.0
20         840.0
21         634.0
22         820.0
23        1100.0
24        1265.0
25          15.0
26         600.0
27          12.0
28          45.0
29         588.0
          ...   
55003        NaN
55004      706.0
55005       80.0
55006      568.0
55007      984.0
55008      548.0
55009        NaN
55010      457.0
55011     8530.0
55012        NaN
55013      262.0
55014        NaN
55015      760.0
55016        NaN
55017      791.0
55018    12816.0
55019      883.0
55020     1836.0
55021      477.0
55022      459.0
55023     1240.0
55024      107.0
55025     1200.0
55026      198.0
55027      624.0
55028        0.0
55029        NaN
55030       40.0
55031       11.0
55032      338.0
Name: elevation_ft, Length: 55033, dtype: float64
Select several columns:
In [7]:
df[['type', 'name', 'id']]
Out[7]:
type name id
0 heliport Total Rf Heliport 6523
1 small_airport Aero B Ranch Airport 323361
2 small_airport Lowell Field 6524
3 small_airport Epps Airpark 6525
4 closed Newport Hospital & Clinic Heliport 6526
5 small_airport Fulton Airport 322127
6 small_airport Cordes Airport 6527
7 small_airport Goldstone /Gts/ Airport 6528
8 small_airport Williams Ag Airport 324424
9 heliport Kitchen Creek Helibase Heliport 322658
10 closed Cass Field 6529
11 small_airport Grass Patch Airport 6531
12 heliport Ringhaver Heliport 6532
13 small_airport River Oak Airport 6533
14 small_airport Lt World Airport 6534
15 heliport Caffrey Heliport 6535
16 heliport Kaupulehu Heliport 6536
17 small_airport Delta Shores Airport 6537
18 small_airport Goltl Airport 322581
19 heliport Bailey Generation Station Heliport 6538
20 small_airport Hammer Airport 6539
21 heliport St Mary Medical Center Heliport 6540
22 small_airport Hayenga's Cant Find Farms Airport 6541
23 small_airport Hayden Farm Airport 6542
24 small_airport Robbins Roost Airport 6543
25 heliport Shell Chemical East Site Heliport 45437
26 heliport Ac & R Components Heliport 6544
27 small_airport Lejeune Airport 6545
28 small_airport Slater Field 6546
29 heliport Dow Chemical Heliport 6547
... ... ... ...
55003 medium_airport Anshan Air Base 30646
55004 medium_airport Longjia Airport 27237
55005 medium_airport Changhai Airport 300858
55006 medium_airport Chaoyang Airport 30827
55007 medium_airport Wudalianchi Dedu Airport 327349
55008 small_airport Fuxin Airport 324338
55009 medium_airport Dongji Aiport 313994
55010 large_airport Taiping Airport 27238
55011 medium_airport Heihe Airport 31576
55012 small_airport Jilin Airport 31701
55013 medium_airport Jiamusi Airport 27239
55014 medium_airport Jiansanjiang Airport 327450
55015 medium_airport Jixi Xingkaihu Airport 313337
55016 medium_airport Jinzhou Airport 31706
55017 medium_airport Lindu Airport 307012
55018 medium_airport Yushu Batang Airport 300516
55019 medium_airport Mudanjiang Hailang International Airport 27240
55020 medium_airport Gu-Lian Airport 301193
55021 medium_airport Qiqihar Sanjiazi Airport 27241
55022 medium_airport Songyuan Chaganhu Airport 327451
55023 small_airport Tahe Airport 307017
55024 large_airport Zhoushuizi Airport 27242
55025 medium_airport Tonghua Sanyuanpu Airport 307013
55026 large_airport Taoxian Airport 27243
55027 medium_airport Yanji Chaoyangchuan Airport 27244
55028 medium_airport Yingkou Lanqi Airport 317861
55029 medium_airport Shenyang Dongta Airport 32753
55030 heliport Sealand Helipad 46378
55031 small_airport Glorioso Islands Airstrip 307326
55032 small_airport Satsuma Iōjima Airport 313629

55033 rows × 3 columns

Select a range of rows:
In [5]:
df[10:20]
Out[5]:
id ident type name latitude_deg longitude_deg elevation_ft continent iso_country iso_region municipality scheduled_service gps_code iata_code local_code home_link wikipedia_link keywords
10 6529 00CO closed Cass Field 40.622202 -104.344002 4830.0 NaN US US-CO Briggsdale no NaN NaN NaN NaN NaN 00CO
11 6531 00FA small_airport Grass Patch Airport 28.645500 -82.219002 53.0 NaN US US-FL Bushnell no 00FA NaN 00FA NaN NaN NaN
12 6532 00FD heliport Ringhaver Heliport 28.846600 -82.345398 25.0 NaN US US-FL Riverview no 00FD NaN 00FD NaN NaN NaN
13 6533 00FL small_airport River Oak Airport 27.230900 -80.969200 35.0 NaN US US-FL Okeechobee no 00FL NaN 00FL NaN NaN NaN
14 6534 00GA small_airport Lt World Airport 33.767502 -84.068298 700.0 NaN US US-GA Lithonia no 00GA NaN 00GA NaN NaN NaN
15 6535 00GE heliport Caffrey Heliport 33.884201 -84.733902 957.0 NaN US US-GA Hiram no 00GE NaN 00GE NaN NaN NaN
16 6536 00HI heliport Kaupulehu Heliport 19.832715 -155.980233 43.0 NaN US US-HI Kailua/Kona no 00HI NaN 00HI NaN NaN NaN
17 6537 00ID small_airport Delta Shores Airport 48.145302 -116.213997 2064.0 NaN US US-ID Clark Fork no 00ID NaN 00ID NaN NaN NaN
18 322581 00IG small_airport Goltl Airport 39.724028 -101.395994 3359.0 NaN US US-KS McDonald no 00IG NaN 00IG NaN NaN NaN
19 6538 00II heliport Bailey Generation Station Heliport 41.644501 -87.122803 600.0 NaN US US-IN Chesterton no 00II NaN 00II NaN NaN NaN
Select one row:
In [6]:
df.iloc[10]
Out[6]:
id                         6529
ident                      00CO
type                     closed
name                 Cass Field
latitude_deg            40.6222
longitude_deg          -104.344
elevation_ft               4830
continent                   NaN
iso_country                  US
iso_region                US-CO
municipality         Briggsdale
scheduled_service            no
gps_code                    NaN
iata_code                   NaN
local_code                  NaN
home_link                   NaN
wikipedia_link              NaN
keywords                   00CO
Name: 10, dtype: object
Summary of the elevation column:
In [7]:
df['elevation_ft'].describe()
Out[7]:
count    48042.000000
mean      1240.580221
std       1602.009446
min      -1266.000000
25%        205.000000
50%        718.000000
75%       1496.750000
max      22000.000000
Name: elevation_ft, dtype: float64
In [8]:
df['elevation_ft'].min()
Out[8]:
-1266.0
Find the row number with the smallest elevation:
In [9]:
min_row = df['elevation_ft'].idxmin()
min_row
Out[9]:
31877
In [10]:
df.iloc[min_row]
Out[10]:
id                                                               4421
ident                                                            LLMZ
type                                                   medium_airport
name                                              Bar Yehuda Airfield
latitude_deg                                                  31.3282
longitude_deg                                                 35.3886
elevation_ft                                                    -1266
continent                                                          AS
iso_country                                                        IL
iso_region                                                       IL-D
municipality                                                   Masada
scheduled_service                                                  no
gps_code                                                         LLMZ
iata_code                                                         MTZ
local_code                                                        NaN
home_link                                                         NaN
wikipedia_link       http://en.wikipedia.org/wiki/Bar_Yehuda_Airfield
keywords                                              Masada Airfield
Name: 31877, dtype: object
Find all airports with elevation below -100 ft:
In [11]:
df['elevation_ft'] < -100
Out[11]:
0        False
1        False
2        False
3        False
4        False
5        False
6        False
7        False
8        False
9        False
10       False
11       False
12       False
13       False
14       False
15       False
16       False
17       False
18       False
19       False
20       False
21       False
22       False
23       False
24       False
25       False
26       False
27       False
28       False
29       False
         ...  
55003    False
55004    False
55005    False
55006    False
55007    False
55008    False
55009    False
55010    False
55011    False
55012    False
55013    False
55014    False
55015    False
55016    False
55017    False
55018    False
55019    False
55020    False
55021    False
55022    False
55023    False
55024    False
55025    False
55026    False
55027    False
55028    False
55029    False
55030    False
55031    False
55032    False
Name: elevation_ft, Length: 55033, dtype: bool
In [12]:
df[df['elevation_ft'] < -100]
Out[12]:
id ident type name latitude_deg longitude_deg elevation_ft continent iso_country iso_region municipality scheduled_service gps_code iata_code local_code home_link wikipedia_link keywords
26265 19422 KBWC small_airport Brawley Municipal Airport 32.992901 -115.516998 -128.0 NaN US US-CA Brawley no KBWC BWC BWC NaN http://en.wikipedia.org/wiki/Brawley_Municipal... NaN
26388 19514 KCLR small_airport Cliff Hatfield Memorial Airport 33.131500 -115.521004 -182.0 NaN US US-CA Calipatria no KCLR CLR CLR NaN http://en.wikipedia.org/wiki/Cliff_Hatfield_Me... NaN
27731 20283 KL06 small_airport Furnace Creek Airport 36.463799 -116.880997 -210.0 NaN US US-CA Death Valley National Park no NaN DTH L06 NaN http://en.wikipedia.org/wiki/Furnace_Creek_Air... NaN
30138 21222 KTRM medium_airport Jacqueline Cochran Regional Airport 33.626701 -116.160004 -115.0 NaN US US-CA Palm Springs no KTRM TRM TRM http://www.rcjcra.com/ http://en.wikipedia.org/wiki/Jacqueline_Cochra... Thermal Airport, Desert Resorts Regional Airpo...
31862 4416 LLEY small_airport Ein Yahav Airfield 30.621700 35.203300 -164.0 AS IL IL-D Sapir no LLEY EIY NaN NaN http://en.wikipedia.org/wiki/Ein_Yahav_Airfield Sapir Airfield
31877 4421 LLMZ medium_airport Bar Yehuda Airfield 31.328199 35.388599 -1266.0 AS IL IL-D Masada no LLMZ MTZ NaN NaN http://en.wikipedia.org/wiki/Bar_Yehuda_Airfield Masada Airfield
Add a new column with elevations in meters:
In [21]:
df['elevation_meters'] = df['elevation_ft']/3.28
df
Out[21]:
id ident type name latitude_deg longitude_deg elevation_ft continent iso_country iso_region municipality scheduled_service gps_code iata_code local_code home_link wikipedia_link keywords elevation_meters
0 6523 00A heliport Total Rf Heliport 40.070801 -74.933601 11.0 NaN US US-PA Bensalem no 00A NaN 00A NaN NaN NaN 3.353659
1 323361 00AA small_airport Aero B Ranch Airport 38.704022 -101.473911 3435.0 NaN US US-KS Leoti no 00AA NaN 00AA NaN NaN NaN 1047.256098
2 6524 00AK small_airport Lowell Field 59.949200 -151.695999 450.0 NaN US US-AK Anchor Point no 00AK NaN 00AK NaN NaN NaN 137.195122
3 6525 00AL small_airport Epps Airpark 34.864799 -86.770302 820.0 NaN US US-AL Harvest no 00AL NaN 00AL NaN NaN NaN 250.000000
4 6526 00AR closed Newport Hospital & Clinic Heliport 35.608700 -91.254898 237.0 NaN US US-AR Newport no NaN NaN NaN NaN NaN 00AR 72.256098
5 322127 00AS small_airport Fulton Airport 34.942803 -97.818019 1100.0 NaN US US-OK Alex no 00AS NaN 00AS NaN NaN NaN 335.365854
6 6527 00AZ small_airport Cordes Airport 34.305599 -112.165001 3810.0 NaN US US-AZ Cordes no 00AZ NaN 00AZ NaN NaN NaN 1161.585366
7 6528 00CA small_airport Goldstone /Gts/ Airport 35.350498 -116.888000 3038.0 NaN US US-CA Barstow no 00CA NaN 00CA NaN NaN NaN 926.219512
8 324424 00CL small_airport Williams Ag Airport 39.427188 -121.763427 87.0 NaN US US-CA Biggs no 00CL NaN 00CL NaN NaN NaN 26.524390
9 322658 00CN heliport Kitchen Creek Helibase Heliport 32.727374 -116.459742 3350.0 NaN US US-CA Pine Valley no 00CN NaN 00CN NaN NaN NaN 1021.341463
10 6529 00CO closed Cass Field 40.622202 -104.344002 4830.0 NaN US US-CO Briggsdale no NaN NaN NaN NaN NaN 00CO 1472.560976
11 6531 00FA small_airport Grass Patch Airport 28.645500 -82.219002 53.0 NaN US US-FL Bushnell no 00FA NaN 00FA NaN NaN NaN 16.158537
12 6532 00FD heliport Ringhaver Heliport 28.846600 -82.345398 25.0 NaN US US-FL Riverview no 00FD NaN 00FD NaN NaN NaN 7.621951
13 6533 00FL small_airport River Oak Airport 27.230900 -80.969200 35.0 NaN US US-FL Okeechobee no 00FL NaN 00FL NaN NaN NaN 10.670732
14 6534 00GA small_airport Lt World Airport 33.767502 -84.068298 700.0 NaN US US-GA Lithonia no 00GA NaN 00GA NaN NaN NaN 213.414634
15 6535 00GE heliport Caffrey Heliport 33.884201 -84.733902 957.0 NaN US US-GA Hiram no 00GE NaN 00GE NaN NaN NaN 291.768293
16 6536 00HI heliport Kaupulehu Heliport 19.832715 -155.980233 43.0 NaN US US-HI Kailua/Kona no 00HI NaN 00HI NaN NaN NaN 13.109756
17 6537 00ID small_airport Delta Shores Airport 48.145302 -116.213997 2064.0 NaN US US-ID Clark Fork no 00ID NaN 00ID NaN NaN NaN 629.268293
18 322581 00IG small_airport Goltl Airport 39.724028 -101.395994 3359.0 NaN US US-KS McDonald no 00IG NaN 00IG NaN NaN NaN 1024.085366
19 6538 00II heliport Bailey Generation Station Heliport 41.644501 -87.122803 600.0 NaN US US-IN Chesterton no 00II NaN 00II NaN NaN NaN 182.926829
20 6539 00IL small_airport Hammer Airport 41.978401 -89.560402 840.0 NaN US US-IL Polo no 00IL NaN 00IL NaN NaN NaN 256.097561
21 6540 00IN heliport St Mary Medical Center Heliport 41.511398 -87.260597 634.0 NaN US US-IN Hobart no 00IN NaN 00IN NaN NaN NaN 193.292683
22 6541 00IS small_airport Hayenga's Cant Find Farms Airport 40.025600 -89.122902 820.0 NaN US US-IL Kings no 00IS NaN 00IS NaN NaN NaN 250.000000
23 6542 00KS small_airport Hayden Farm Airport 38.727798 -94.930496 1100.0 NaN US US-KS Gardner no 00KS NaN 00KS NaN NaN NaN 335.365854
24 6543 00KY small_airport Robbins Roost Airport 37.409401 -84.619698 1265.0 NaN US US-KY Stanford no 00KY NaN 00KY NaN NaN NaN 385.670732
25 45437 00LA heliport Shell Chemical East Site Heliport 30.191944 -90.980833 15.0 NaN US US-LA Gonzales no 00LA NaN 00LA NaN NaN NaN 4.573171
26 6544 00LL heliport Ac & R Components Heliport 39.665298 -89.705597 600.0 NaN US US-IL Chatham no 00LL NaN 00LL NaN NaN NaN 182.926829
27 6545 00LS small_airport Lejeune Airport 30.136299 -92.429398 12.0 NaN US US-LA Esterwood no 00LS NaN 00LS NaN NaN NaN 3.658537
28 6546 00MD small_airport Slater Field 38.757099 -75.753799 45.0 NaN US US-MD Federalsburg no 00MD NaN 00MD NaN NaN NaN 13.719512
29 6547 00MI heliport Dow Chemical Heliport 43.949402 -86.416702 588.0 NaN US US-MI Ludington no 00MI NaN 00MI NaN NaN NaN 179.268293
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
55003 30646 ZYAS medium_airport Anshan Air Base 41.105301 122.853996 NaN AS CN CN-21 Anshan yes ZYAS AOG NaN NaN https://en.wikipedia.org/wiki/Anshan_Teng%27ao... NaN NaN
55004 27237 ZYCC medium_airport Longjia Airport 43.996201 125.684998 706.0 AS CN CN-22 Changchun yes ZYCC CGQ NaN NaN http://en.wikipedia.org/wiki/Changchun_Longjia... NaN 215.243902
55005 300858 ZYCH medium_airport Changhai Airport 39.266667 122.666944 80.0 AS CN CN-21 Changhai no ZYCH CNI NaN NaN http://en.wikipedia.org/wiki/Changhai_Airport NaN 24.390244
55006 30827 ZYCY medium_airport Chaoyang Airport 41.538101 120.434998 568.0 AS CN CN-21 Chaoyang yes ZYCY CHG NaN NaN https://en.wikipedia.org/wiki/Chaoyang_Airport NaN 173.170732
55007 327349 ZYDU medium_airport Wudalianchi Dedu Airport 48.445000 126.133000 984.0 AS CN CN-23 Wudalianchi yes ZYDU DTU NaN NaN https://en.wikipedia.org/wiki/Wudalianchi_Dedu... NaN 300.000000
55008 324338 ZYFX small_airport Fuxin Airport 42.069014 121.718122 548.0 AS CN CN-21 Fuxin no ZYFX NaN NaN NaN NaN NaN 167.073171
55009 313994 ZYFY medium_airport Dongji Aiport 48.199494 134.366447 NaN AS CN CN-23 Fuyuan yes ZYFY FYJ NaN NaN https://en.wikipedia.org/wiki/Fuyuan_Dongji_Ai... NaN NaN
55010 27238 ZYHB large_airport Taiping Airport 45.623402 126.250000 457.0 AS CN CN-23 Harbin yes ZYHB HRB NaN NaN http://en.wikipedia.org/wiki/Harbin_Taiping_In... NaN 139.329268
55011 31576 ZYHE medium_airport Heihe Airport 50.171621 127.308884 8530.0 AS CN CN-23 Heihe yes ZYHE HEK NaN NaN http://en.wikipedia.org/wiki/Heihe_Airport NaN 2600.609756
55012 31701 ZYJL small_airport Jilin Airport 44.002201 126.396004 NaN AS CN CN-22 Jilin no ZYJL JIL NaN NaN https://en.wikipedia.org/wiki/Jilin_Ertaizi_Ai... NaN NaN
55013 27239 ZYJM medium_airport Jiamusi Airport 46.843399 130.464996 262.0 AS CN CN-23 Jiamusi yes ZYJM JMU NaN NaN http://en.wikipedia.org/wiki/Jiamusi_Airport NaN 79.878049
55014 327450 ZYJS medium_airport Jiansanjiang Airport 47.110000 132.660278 NaN AS CN CN-23 Jiansanjiang yes ZYJS JSJ NaN NaN https://en.wikipedia.org/wiki/Jiansanjiang_Air... NaN NaN
55015 313337 ZYJX medium_airport Jixi Xingkaihu Airport 45.293000 131.193000 760.0 AS CN CN-23 Jixi yes ZYJX JXA NaN NaN http://en.wikipedia.org/wiki/Jixi_Xingkaihu_Ai... NaN 231.707317
55016 31706 ZYJZ medium_airport Jinzhou Airport 41.101398 121.061997 NaN AS CN CN-21 Jinzhou yes ZYJZ JNZ NaN NaN http://en.wikipedia.org/wiki/Jinzhou_Airport Xiaolingzi Air Base NaN
55017 307012 ZYLD medium_airport Lindu Airport 47.752056 129.019125 791.0 AS CN CN-23 Yichun yes ZYLD LDS NaN NaN http://en.wikipedia.org/wiki/Yichun_Lindu_Airport Yichun Shi Airport 241.158537
55018 300516 ZYLS medium_airport Yushu Batang Airport 32.836389 97.036389 12816.0 AS CN CN-63 Yushu no ZYLS YUS NaN NaN http://en.wikipedia.org/wiki/Yushu_Batang_Airport NaN 3907.317073
55019 27240 ZYMD medium_airport Mudanjiang Hailang International Airport 44.524101 129.569000 883.0 AS CN CN-23 Mudanjiang yes ZYMD MDG NaN NaN http://en.wikipedia.org/wiki/Mudanjiang_Airport Mudanjiang 269.207317
55020 301193 ZYMH medium_airport Gu-Lian Airport 52.912778 122.430000 1836.0 AS CN CN-23 Mohe yes ZYMH OHE NaN NaN http://en.wikipedia.org/wiki/Mohe_Gulian_Airport NaN 559.756098
55021 27241 ZYQQ medium_airport Qiqihar Sanjiazi Airport 47.239601 123.917999 477.0 AS CN CN-23 Qiqihar yes ZYQQ NDG NaN NaN http://en.wikipedia.org/wiki/Qiqihar_Airport NaN 145.426829
55022 327451 ZYSQ medium_airport Songyuan Chaganhu Airport 44.938114 124.550178 459.0 AS CN CN-22 Qian Gorlos Mongol Autonomous County yes ZYSQ YSQ NaN NaN https://en.wikipedia.org/wiki/Songyuan_Chaganh... NaN 139.939024
55023 307017 ZYTH small_airport Tahe Airport 52.224444 124.720222 1240.0 AS CN CN-23 Tahe no ZYTH NaN NaN NaN NaN NaN 378.048780
55024 27242 ZYTL large_airport Zhoushuizi Airport 38.965698 121.539001 107.0 AS CN CN-21 Dalian yes ZYTL DLC NaN NaN http://en.wikipedia.org/wiki/Dalian_Zhoushuizi... Dalian Air Base 32.621951
55025 307013 ZYTN medium_airport Tonghua Sanyuanpu Airport 42.253889 125.703333 1200.0 AS CN CN-22 Tonghua yes ZYTN TNH NaN NaN http://en.wikipedia.org/wiki/Tonghua_Sanyuanpu... Tonghua Liuhe Airport 365.853659
55026 27243 ZYTX large_airport Taoxian Airport 41.639801 123.483002 198.0 AS CN CN-21 Shenyang yes ZYTX SHE NaN NaN http://en.wikipedia.org/wiki/Shenyang_Taoxian_... NaN 60.365854
55027 27244 ZYYJ medium_airport Yanji Chaoyangchuan Airport 42.882801 129.451004 624.0 AS CN CN-22 Yanji yes ZYYJ YNJ NaN NaN http://en.wikipedia.org/wiki/Yanji_Chaoyangchu... NaN 190.243902
55028 317861 ZYYK medium_airport Yingkou Lanqi Airport 40.542524 122.358600 0.0 AS CN CN-21 Yingkou yes ZYYK YKH NaN NaN https://en.wikipedia.org/wiki/Yingkou_Lanqi_Ai... NaN 0.000000
55029 32753 ZYYY medium_airport Shenyang Dongta Airport 41.784401 123.496002 NaN AS CN CN-21 Shenyang no ZYYY NaN NaN NaN NaN NaN NaN
55030 46378 ZZ-0001 heliport Sealand Helipad 51.894444 1.482500 40.0 EU GB GB-ENG Sealand no NaN NaN NaN http://www.sealandgov.org/ http://en.wikipedia.org/wiki/Principality_of_S... Roughs Tower Helipad 12.195122
55031 307326 ZZ-0002 small_airport Glorioso Islands Airstrip -11.584278 47.296389 11.0 AF TF TF-U-A Grande Glorieuse no NaN NaN NaN NaN NaN NaN 3.353659
55032 313629 ZZZZ small_airport Satsuma Iōjima Airport 30.784722 130.270556 338.0 AS JP JP-46 Mishima-Mura no RJX7 NaN NaN NaN http://wikimapia.org/6705190/Satsuma-Iwo-jima-... SATSUMA,IWOJIMA,RJX7 103.048780

55033 rows × 19 columns

Count the number of airports of each type:
In [13]:
df['type'].value_counts()
Out[13]:
small_airport     33965
heliport          11276
medium_airport     4547
closed             3581
seaplane_base      1015
large_airport       626
balloonport          23
Name: type, dtype: int64
go top

2. Plotting Airport Locations


Goal: Use Bokeh to plot locations of all airports.

In [4]:
import bokeh.plotting as bk
bk.output_notebook() # show plots in the notebook
Loading BokehJS ...
In [5]:
w = 750
h = 400

p = bk.figure(plot_width=w, plot_height=h)
p.circle(df["longitude_deg"], df["latitude_deg"], size=2, color='red', alpha = 0.1)
bk.show(p)

Background map:

In [6]:
from bokeh.tile_providers import CARTODBPOSITRON_RETINA as world_map

left = -20_000_000
right = 20_000_000
top = 1_000_000
bottom = -1_000_000

p = bk.figure(plot_width=w, 
              plot_height=h,  
              x_range=(left, right), 
              y_range=(top,bottom))

p.add_tile(world_map)
bk.show(p)

From latitude and longitude to Mercator coordinates


Note:
  • The data gives airport coordinates in terms of longitude and latitude.
  • The map uses the Mercator coordinates $(x, y)$.
  • In order to plot airports on the map we need to recalculate their coordinates:
$$ \left\{ \begin{align} x \ \ = & \ \ \frac{R\cdot \pi}{180}\cdot {\text{longitude}} \\[2mm] y \ \ = & \ \ R\cdot \log\left(\tan \left({\frac{360}{\pi}}\cdot{\text{latitude}} + \frac{\pi}{4} \right) \right) \end{align} \right. $$ $ R =$ radius of the Earth = 6,378,137 meters.
In [7]:
import numpy as np

R = 6378137

def lon2x(lon):
    x = R*(np.pi/180)*lon
    return x

def lat2y(lat):
    y = R*np.log(np.tan((np.pi/360.0)*lat + np.pi/4.0))
    return y

Add new columns to the dataframe with Mercator coordinates of airports:

In [8]:
df['x'] = lon2x(df["longitude_deg"])
df['y'] = lat2y(df["latitude_deg"])
df
Out[8]:
id ident type name latitude_deg longitude_deg elevation_ft continent iso_country iso_region municipality scheduled_service gps_code iata_code local_code home_link wikipedia_link keywords x y
0 6523 00A heliport Total Rf Heliport 40.070801 -74.933601 11.0 NaN US US-PA Bensalem no 00A NaN 00A NaN NaN NaN -8.341570e+06 4.876236e+06
1 323361 00AA small_airport Aero B Ranch Airport 38.704022 -101.473911 3435.0 NaN US US-KS Leoti no 00AA NaN 00AA NaN NaN NaN -1.129602e+07 4.679364e+06
2 6524 00AK small_airport Lowell Field 59.949200 -151.695999 450.0 NaN US US-AK Anchor Point no 00AK NaN 00AK NaN NaN NaN -1.688672e+07 8.388436e+06
3 6525 00AL small_airport Epps Airpark 34.864799 -86.770302 820.0 NaN US US-AL Harvest no 00AL NaN 00AL NaN NaN NaN -9.659226e+06 4.145523e+06
4 6526 00AR closed Newport Hospital & Clinic Heliport 35.608700 -91.254898 237.0 NaN US US-AR Newport no NaN NaN NaN NaN NaN 00AR -1.015845e+07 4.246912e+06
5 322127 00AS small_airport Fulton Airport 34.942803 -97.818019 1100.0 NaN US US-OK Alex no 00AS NaN 00AS NaN NaN NaN -1.088905e+07 4.156111e+06
6 6527 00AZ small_airport Cordes Airport 34.305599 -112.165001 3810.0 NaN US US-AZ Cordes no 00AZ NaN 00AZ NaN NaN NaN -1.248615e+07 4.069911e+06
7 6528 00CA small_airport Goldstone /Gts/ Airport 35.350498 -116.888000 3038.0 NaN US US-CA Barstow no 00CA NaN 00CA NaN NaN NaN -1.301191e+07 4.211615e+06
8 324424 00CL small_airport Williams Ag Airport 39.427188 -121.763427 87.0 NaN US US-CA Biggs no 00CL NaN 00CL NaN NaN NaN -1.355464e+07 4.783049e+06
9 322658 00CN heliport Kitchen Creek Helibase Heliport 32.727374 -116.459742 3350.0 NaN US US-CA Pine Valley no 00CN NaN 00CN NaN NaN NaN -1.296424e+07 3.859173e+06
10 6529 00CO closed Cass Field 40.622202 -104.344002 4830.0 NaN US US-CO Briggsdale no NaN NaN NaN NaN NaN 00CO -1.161552e+07 4.956775e+06
11 6531 00FA small_airport Grass Patch Airport 28.645500 -82.219002 53.0 NaN US US-FL Bushnell no 00FA NaN 00FA NaN NaN NaN -9.152577e+06 3.330603e+06
12 6532 00FD heliport Ringhaver Heliport 28.846600 -82.345398 25.0 NaN US US-FL Riverview no 00FD NaN 00FD NaN NaN NaN -9.166648e+06 3.356136e+06
13 6533 00FL small_airport River Oak Airport 27.230900 -80.969200 35.0 NaN US US-FL Okeechobee no 00FL NaN 00FL NaN NaN NaN -9.013450e+06 3.152349e+06
14 6534 00GA small_airport Lt World Airport 33.767502 -84.068298 700.0 NaN US US-GA Lithonia no 00GA NaN 00GA NaN NaN NaN -9.358440e+06 3.997626e+06
15 6535 00GE heliport Caffrey Heliport 33.884201 -84.733902 957.0 NaN US US-GA Hiram no 00GE NaN 00GE NaN NaN NaN -9.432535e+06 4.013264e+06
16 6536 00HI heliport Kaupulehu Heliport 19.832715 -155.980233 43.0 NaN US US-HI Kailua/Kona no 00HI NaN 00HI NaN NaN NaN -1.736364e+07 2.253224e+06
17 6537 00ID small_airport Delta Shores Airport 48.145302 -116.213997 2064.0 NaN US US-ID Clark Fork no 00ID NaN 00ID NaN NaN NaN -1.293688e+07 6.131062e+06
18 322581 00IG small_airport Goltl Airport 39.724028 -101.395994 3359.0 NaN US US-KS McDonald no 00IG NaN 00IG NaN NaN NaN -1.128735e+07 4.825919e+06
19 6538 00II heliport Bailey Generation Station Heliport 41.644501 -87.122803 600.0 NaN US US-IN Chesterton no 00II NaN 00II NaN NaN NaN -9.698466e+06 5.107875e+06
20 6539 00IL small_airport Hammer Airport 41.978401 -89.560402 840.0 NaN US US-IL Polo no 00IL NaN 00IL NaN NaN NaN -9.969818e+06 5.157745e+06
21 6540 00IN heliport St Mary Medical Center Heliport 41.511398 -87.260597 634.0 NaN US US-IN Hobart no 00IN NaN 00IN NaN NaN NaN -9.713805e+06 5.088068e+06
22 6541 00IS small_airport Hayenga's Cant Find Farms Airport 40.025600 -89.122902 820.0 NaN US US-IL Kings no 00IS NaN 00IS NaN NaN NaN -9.921116e+06 4.869663e+06
23 6542 00KS small_airport Hayden Farm Airport 38.727798 -94.930496 1100.0 NaN US US-KS Gardner no 00KS NaN 00KS NaN NaN NaN -1.056761e+07 4.682756e+06
24 6543 00KY small_airport Robbins Roost Airport 37.409401 -84.619698 1265.0 NaN US US-KY Stanford no 00KY NaN 00KY NaN NaN NaN -9.419822e+06 4.496327e+06
25 45437 00LA heliport Shell Chemical East Site Heliport 30.191944 -90.980833 15.0 NaN US US-LA Gonzales no 00LA NaN 00LA NaN NaN NaN -1.012794e+07 3.528246e+06
26 6544 00LL heliport Ac & R Components Heliport 39.665298 -89.705597 600.0 NaN US US-IL Chatham no 00LL NaN 00LL NaN NaN NaN -9.985981e+06 4.817423e+06
27 6545 00LS small_airport Lejeune Airport 30.136299 -92.429398 12.0 NaN US US-LA Esterwood no 00LS NaN 00LS NaN NaN NaN -1.028919e+07 3.521082e+06
28 6546 00MD small_airport Slater Field 38.757099 -75.753799 45.0 NaN US US-MD Federalsburg no 00MD NaN 00MD NaN NaN NaN -8.432874e+06 4.686938e+06
29 6547 00MI heliport Dow Chemical Heliport 43.949402 -86.416702 588.0 NaN US US-MI Ludington no 00MI NaN 00MI NaN NaN NaN -9.619863e+06 5.457615e+06
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
55003 30646 ZYAS medium_airport Anshan Air Base 41.105301 122.853996 NaN AS CN CN-21 Anshan yes ZYAS AOG NaN NaN https://en.wikipedia.org/wiki/Anshan_Teng%27ao... NaN 1.367604e+07 5.027886e+06
55004 27237 ZYCC medium_airport Longjia Airport 43.996201 125.684998 706.0 AS CN CN-22 Changchun yes ZYCC CGQ NaN NaN http://en.wikipedia.org/wiki/Changchun_Longjia... NaN 1.399119e+07 5.464854e+06
55005 300858 ZYCH medium_airport Changhai Airport 39.266667 122.666944 80.0 AS CN CN-21 Changhai no ZYCH CNI NaN NaN http://en.wikipedia.org/wiki/Changhai_Airport NaN 1.365522e+07 4.759942e+06
55006 30827 ZYCY medium_airport Chaoyang Airport 41.538101 120.434998 568.0 AS CN CN-21 Chaoyang yes ZYCY CHG NaN NaN https://en.wikipedia.org/wiki/Chaoyang_Airport NaN 1.340676e+07 5.092038e+06
55007 327349 ZYDU medium_airport Wudalianchi Dedu Airport 48.445000 126.133000 984.0 AS CN CN-23 Wudalianchi yes ZYDU DTU NaN NaN https://en.wikipedia.org/wiki/Wudalianchi_Dedu... NaN 1.404106e+07 6.181209e+06
55008 324338 ZYFX small_airport Fuxin Airport 42.069014 121.718122 548.0 AS CN CN-21 Fuxin no ZYFX NaN NaN NaN NaN NaN 1.354960e+07 5.171323e+06
55009 313994 ZYFY medium_airport Dongji Aiport 48.199494 134.366447 NaN AS CN CN-23 Fuyuan yes ZYFY FYJ NaN NaN https://en.wikipedia.org/wiki/Fuyuan_Dongji_Ai... NaN 1.495760e+07 6.140108e+06
55010 27238 ZYHB large_airport Taiping Airport 45.623402 126.250000 457.0 AS CN CN-23 Harbin yes ZYHB HRB NaN NaN http://en.wikipedia.org/wiki/Harbin_Taiping_In... NaN 1.405409e+07 5.720203e+06
55011 31576 ZYHE medium_airport Heihe Airport 50.171621 127.308884 8530.0 AS CN CN-23 Heihe yes ZYHE HEK NaN NaN http://en.wikipedia.org/wiki/Heihe_Airport NaN 1.417196e+07 6.476051e+06
55012 31701 ZYJL small_airport Jilin Airport 44.002201 126.396004 NaN AS CN CN-22 Jilin no ZYJL JIL NaN NaN https://en.wikipedia.org/wiki/Jilin_Ertaizi_Ai... NaN 1.407034e+07 5.465783e+06
55013 27239 ZYJM medium_airport Jiamusi Airport 46.843399 130.464996 262.0 AS CN CN-23 Jiamusi yes ZYJM JMU NaN NaN http://en.wikipedia.org/wiki/Jiamusi_Airport NaN 1.452330e+07 5.916550e+06
55014 327450 ZYJS medium_airport Jiansanjiang Airport 47.110000 132.660278 NaN AS CN CN-23 Jiansanjiang yes ZYJS JSJ NaN NaN https://en.wikipedia.org/wiki/Jiansanjiang_Air... NaN 1.476767e+07 5.960047e+06
55015 313337 ZYJX medium_airport Jixi Xingkaihu Airport 45.293000 131.193000 760.0 AS CN CN-23 Jixi yes ZYJX JXA NaN NaN http://en.wikipedia.org/wiki/Jixi_Xingkaihu_Ai... NaN 1.460434e+07 5.667767e+06
55016 31706 ZYJZ medium_airport Jinzhou Airport 41.101398 121.061997 NaN AS CN CN-21 Jinzhou yes ZYJZ JNZ NaN NaN http://en.wikipedia.org/wiki/Jinzhou_Airport Xiaolingzi Air Base 1.347656e+07 5.027309e+06
55017 307012 ZYLD medium_airport Lindu Airport 47.752056 129.019125 791.0 AS CN CN-23 Yichun yes ZYLD LDS NaN NaN http://en.wikipedia.org/wiki/Yichun_Lindu_Airport Yichun Shi Airport 1.436234e+07 6.065704e+06
55018 300516 ZYLS medium_airport Yushu Batang Airport 32.836389 97.036389 12816.0 AS CN CN-63 Yushu no ZYLS YUS NaN NaN http://en.wikipedia.org/wiki/Yushu_Batang_Airport NaN 1.080204e+07 3.873607e+06
55019 27240 ZYMD medium_airport Mudanjiang Hailang International Airport 44.524101 129.569000 883.0 AS CN CN-23 Mudanjiang yes ZYMD MDG NaN NaN http://en.wikipedia.org/wiki/Mudanjiang_Airport Mudanjiang 1.442356e+07 5.546910e+06
55020 301193 ZYMH medium_airport Gu-Lian Airport 52.912778 122.430000 1836.0 AS CN CN-23 Mohe yes ZYMH OHE NaN NaN http://en.wikipedia.org/wiki/Mohe_Gulian_Airport NaN 1.362885e+07 6.966880e+06
55021 27241 ZYQQ medium_airport Qiqihar Sanjiazi Airport 47.239601 123.917999 477.0 AS CN CN-23 Qiqihar yes ZYQQ NDG NaN NaN http://en.wikipedia.org/wiki/Qiqihar_Airport NaN 1.379449e+07 5.981271e+06
55022 327451 ZYSQ medium_airport Songyuan Chaganhu Airport 44.938114 124.550178 459.0 AS CN CN-22 Qian Gorlos Mongol Autonomous County yes ZYSQ YSQ NaN NaN https://en.wikipedia.org/wiki/Songyuan_Chaganh... NaN 1.386486e+07 5.611784e+06
55023 307017 ZYTH small_airport Tahe Airport 52.224444 124.720222 1240.0 AS CN CN-23 Tahe no ZYTH NaN NaN NaN NaN NaN 1.388379e+07 6.840810e+06
55024 27242 ZYTL large_airport Zhoushuizi Airport 38.965698 121.539001 107.0 AS CN CN-21 Dalian yes ZYTL DLC NaN NaN http://en.wikipedia.org/wiki/Dalian_Zhoushuizi... Dalian Air Base 1.352966e+07 4.716759e+06
55025 307013 ZYTN medium_airport Tonghua Sanyuanpu Airport 42.253889 125.703333 1200.0 AS CN CN-22 Tonghua yes ZYTN TNH NaN NaN http://en.wikipedia.org/wiki/Tonghua_Sanyuanpu... Tonghua Liuhe Airport 1.399323e+07 5.199087e+06
55026 27243 ZYTX large_airport Taoxian Airport 41.639801 123.483002 198.0 AS CN CN-21 Shenyang yes ZYTX SHE NaN NaN http://en.wikipedia.org/wiki/Shenyang_Taoxian_... NaN 1.374606e+07 5.107175e+06
55027 27244 ZYYJ medium_airport Yanji Chaoyangchuan Airport 42.882801 129.451004 624.0 AS CN CN-22 Yanji yes ZYYJ YNJ NaN NaN http://en.wikipedia.org/wiki/Yanji_Chaoyangchu... NaN 1.441042e+07 5.294150e+06
55028 317861 ZYYK medium_airport Yingkou Lanqi Airport 40.542524 122.358600 0.0 AS CN CN-21 Yingkou yes ZYYK YKH NaN NaN https://en.wikipedia.org/wiki/Yingkou_Lanqi_Ai... NaN 1.362090e+07 4.945096e+06
55029 32753 ZYYY medium_airport Shenyang Dongta Airport 41.784401 123.496002 NaN AS CN CN-21 Shenyang no ZYYY NaN NaN NaN NaN NaN 1.374751e+07 5.128738e+06
55030 46378 ZZ-0001 heliport Sealand Helipad 51.894444 1.482500 40.0 EU GB GB-ENG Sealand no NaN NaN NaN http://www.sealandgov.org/ http://en.wikipedia.org/wiki/Principality_of_S... Roughs Tower Helipad 1.650311e+05 6.781062e+06
55031 307326 ZZ-0002 small_airport Glorioso Islands Airstrip -11.584278 47.296389 11.0 AF TF TF-U-A Grande Glorieuse no NaN NaN NaN NaN NaN NaN 5.265010e+06 -1.298433e+06
55032 313629 ZZZZ small_airport Satsuma Iōjima Airport 30.784722 130.270556 338.0 AS JP JP-46 Mishima-Mura no RJX7 NaN NaN NaN http://wikimapia.org/6705190/Satsuma-Iwo-jima-... SATSUMA,IWOJIMA,RJX7 1.450165e+07 3.604823e+06

55033 rows × 20 columns

Plot airports on the map:

In [9]:
from bokeh.tile_providers import CARTODBPOSITRON_RETINA as world_map

p = bk.figure(plot_width=w, 
              plot_height=h,   
              x_axis_type="mercator", 
              y_axis_type="mercator",
              x_range=(left, right), 
              y_range=(top, bottom))

p.add_tile(world_map)
p.circle(df["x"], df["y"], radius=400, color = "red", alpha=0.5)

bk.show(p)
In [16]:
from bokeh.models import HoverTool, OpenURL, TapTool


myhover = HoverTool(tooltips= [('Name: ', '@name'), 
                               ('Type: ', '@type'), 
                               ("Wikipedia: ", "@wikipedia_link")])

TOOLS = ['crosshair', 'wheel_zoom', 'box_zoom', 'reset', 'box_select', 'pan', myhover, 'tap']


#get Buffalo airport data
buf = df[df['name'].str.contains("Buffalo Niagara")].iloc[0]
#get coordinates of the Buffalo airport
buf_x = buf['x']
buf_y = buf['y']

radius = 50000

p = bk.figure(plot_width=750, 
              plot_height=500,
              x_axis_type="mercator", 
              y_axis_type="mercator",
              x_range=(buf_x - radius, buf_x + radius), 
              y_range=(buf_y - radius, buf_y + radius), 
              #x_range=(-8_800_000, -8_750_000), 
              #y_range=(5_250_000, 5_350_000), 
              tools=TOOLS)

taptool = p.select(type=TapTool)
url = "@wikipedia_link"
taptool.callback = OpenURL(url=url)

p.add_tile(world_map)
p.circle(x='x', y='y', radius=600, source = df, color='red', alpha=0.5, hover_color='blue', hover_alpha=0.2)
bk.show(p)
Save the plot to an HTML file:
In [10]:
bk.output_file('plot.html')
bk.save(p)
Out[10]:
'/Users/bb/Desktop/CDSE Workshop/plot.html'

☆ ☆ ☆ The End ☆ ☆ ☆

Thank you

</div>