Flight delays (capstone project)

Data wrangling (kind of), some dataset merge process etc...


In [1]:
# date lib
from datetime import datetime

# Pandas and NumPy
import pandas as pd
import numpy as np

In [2]:
# 1. Flight delay: any flight with (real_departure - planned_departure >= 15 minutes)
# 2. The Brazilian Federal Agency for Civil Aviation (ANAC) does not define exactly what is a "flight delay" (in minutes)
# 3. Anyway, the ANAC has a resolution for this subject: https://goo.gl/YBwbMy (last access: nov, 15th, 2017)
# ---
# DELAY, for this analysis, is defined as greater than 15 minutes (local flights only)
DELAY = 15

Local flights dataset. For now, only flights from jan to sep, 2017...

A note about date columns on this dataset

  • In the original dataset (CSV file from ANAC), the date was not in ISO8601 format (e.g. '2017-10-31 09:03:00')
  • To fix this I used regex (regular expression) to transform this column directly on CSV file
  • The original date was "31/10/2017 09:03" (october, 31, 2017 09:03)

The regex:

  • find dates with "([0-9]{2})/([0-9]{2})/([0-9]{4}) ([0-9]{2}):([0-9]{2})", and
  • replace with "\3-\2-\1 \4:\5:00"

In [3]:
#[flights] dataset_01 => all "Active Regular Flights" from 2017, from january to september
#source: http://www.anac.gov.br/assuntos/dados-e-estatisticas/historico-de-voos
#Last access this website: nov, 14th, 2017
flights = pd.read_csv('data/arf2017ISO.csv', sep = ';', parse_dates = True)

In [59]:
flights.head()


Out[59]:
airline flightcode authcode linecode airportA airportB departureest departurereal arrivalest arrivalreal flightstatus problemcode
0 AAL 213 0 I KMIA SBBR 2017-01-02 01:20:00 2017-01-02 01:20:00 2017-01-02 09:00:00 2017-01-02 09:00:00 REALIZADO NaN
1 AAL 213 0 I KMIA SBBR 2017-01-24 01:20:00 2017-01-24 01:20:00 2017-01-24 09:00:00 2017-01-24 09:00:00 REALIZADO NaN
2 AAL 213 0 I KMIA SBBR 2017-01-29 01:20:00 2017-01-29 01:20:00 2017-01-29 09:00:00 2017-01-29 09:00:00 REALIZADO NaN
3 AAL 213 0 I KMIA SBBR 2017-01-23 01:20:00 2017-01-23 01:20:00 2017-01-23 09:00:00 2017-01-23 09:00:00 REALIZADO NaN
4 AAL 213 0 I KMIA SBBR 2017-01-25 01:20:00 2017-01-25 01:20:00 2017-01-25 09:00:00 2017-01-25 09:00:00 REALIZADO NaN

In [5]:
# Airports four-letters-code from object to string
flights['airportA'] = flights['airportA'].astype('str')
flights['airportB'] = flights['airportB'].astype('str')

In [6]:
flights.info()


<class 'pandas.core.frame.DataFrame'>
RangeIndex: 820958 entries, 0 to 820957
Data columns (total 12 columns):
airline          820958 non-null object
flightcode       820958 non-null int64
authcode         820958 non-null object
linecode         820958 non-null object
airportA         820958 non-null object
airportB         820958 non-null object
departureest     773887 non-null object
departurereal    738514 non-null object
arrivalest       773887 non-null object
arrivalreal      738513 non-null object
flightstatus     820958 non-null object
problemcode      302784 non-null object
dtypes: int64(1), object(11)
memory usage: 75.2+ MB

Local airports (list with all the ~600 brazilian public airports)

Source: https://goo.gl/mNFuPt (a XLS spreadsheet in portuguese; last access on nov, 15th, 2017)


In [7]:
# Airports dataset: all brazilian public airports (updated until october, 2017)
airports = pd.read_csv('data/brazilianPublicAirports-out2017.csv', sep = ';')

In [34]:
airports.info()


<class 'pandas.core.frame.DataFrame'>
RangeIndex: 589 entries, 0 to 588
Data columns (total 8 columns):
airport        589 non-null object
airportname    589 non-null object
city           589 non-null object
state          589 non-null object
latitude       589 non-null object
longitude      589 non-null object
altitude       589 non-null object
operation      589 non-null object
dtypes: object(8)
memory usage: 36.9+ KB

In [60]:
airports.head()


Out[60]:
airport airportname city state latitude longitude altitude operation
0 SBAA CONCEIÇÃO DO ARAGUAIA CONCEIÇÃO DO ARAGUAIA PA 8° 20' 55'' S 49° 18' 11'' W 199 m VFR Diurno/Noturno e IFR Diurno
1 SBAE BAURU/AREALVA BAURU E AREALVA SP 22° 9' 28'' S 49° 4' 6'' W 594 m VFR Diurno/Noturno e IFR Diurno/Noturno
2 SBAM AMAPÁ AMAPÁ AP 2° 4' 22'' N 50° 51' 45'' W 14 m VFR Diurno e IFR Diurno
3 SBAQ BARTOLOMEU DE GUSMÃO ARARAQUARA SP 21° 48' 16'' S 48° 8' 25'' W 711 m VFR Diurno/Noturno e IFR Diurno/Noturno
4 SBAR SANTA MARIA ARACAJU SE 10° 59' 7'' S 37° 4' 24'' W 7 m VFR Diurno/Noturno e IFR Diurno/Noturno

List of codes (two letters) used when there was a flight delay (departure)

I have found two lists that define two-letter codes used by the aircraft crew to justify the delay of the flights: a short and a long one.

Source: https://goo.gl/vUC8BX (last access: nov, 15th, 2017)


In [9]:
# ------------------------------------------------------------------
# List of codes (two letters) used to justify a delay on the flight
# - delayCodesShortlist.csv: list with YYY codes
# - delayCodesLongList.csv: list with XXX codes
# ------------------------------------------------------------------
delaycodes = pd.read_csv('data/delayCodesShortlist.csv', sep = ';')
delaycodesLongList = pd.read_csv('data/delayCodesLonglist.csv', sep = ';')

In [10]:
delaycodes.head()


Out[10]:
delaycode delayOrigin duetoweather autorizationdelay delaydescription
0 AA B 0 0 ATRASO AEROPORTO DE ALTERNATIVA de ORDEM TÉCNICA
1 AF A 0 0 FACILIDADES DO AEROPORTO - RESTRIÇÕES DE APOIO
2 AG A 0 0 MIGRAÇÃO/ALFÂNDEGA/SAÚDE
3 AI A 0 0 AEROPORTO DE ORIGEM INTERDITADO
4 AJ B 0 0 AEROPORTO DE DESTINO INTERDITADO

Merging datasets and adjusting the data


In [11]:
# Transform columns with date/time from 'object' to date format
flights['departureest'] = pd.to_datetime(flights['departureest'],errors='ignore')
flights['departurereal'] = pd.to_datetime(flights['departurereal'],errors='ignore')
flights['arrivalest'] = pd.to_datetime(flights['arrivalest'],errors='ignore')
flights['arrivalreal'] = pd.to_datetime(flights['arrivalreal'],errors='ignore')

In [61]:
# Merge "flights" dataset with "airports" in order to identify 
#   local flights (origin and destination are in Brazil)
flights = pd.merge(flights, airports, left_on="airportA", right_on="airport", how='left')

In [63]:
flights = pd.merge(flights, airports, left_on="airportB", right_on="airport", how='left')

In [66]:
flights.head()


Out[66]:
airline flightcode authcode linecode airportA airportB departureest departurereal arrivalest arrivalreal ... altitude_x operation_x airport_y airportname_y city_y state_y latitude_y longitude_y altitude_y operation_y
0 AAL 213 0 I KMIA SBBR 2017-01-02 01:20:00 2017-01-02 01:20:00 2017-01-02 09:00:00 2017-01-02 09:00:00 ... NaN NaN SBBR PRESIDENTE JUSCELINO KUBITSCHEK BRASÍLIA DF 15° 52' 16'' S 47° 55' 7'' W 1066 m VFR Diurno/Noturno e IFR Diurno/Noturno
1 AAL 213 0 I KMIA SBBR 2017-01-24 01:20:00 2017-01-24 01:20:00 2017-01-24 09:00:00 2017-01-24 09:00:00 ... NaN NaN SBBR PRESIDENTE JUSCELINO KUBITSCHEK BRASÍLIA DF 15° 52' 16'' S 47° 55' 7'' W 1066 m VFR Diurno/Noturno e IFR Diurno/Noturno
2 AAL 213 0 I KMIA SBBR 2017-01-29 01:20:00 2017-01-29 01:20:00 2017-01-29 09:00:00 2017-01-29 09:00:00 ... NaN NaN SBBR PRESIDENTE JUSCELINO KUBITSCHEK BRASÍLIA DF 15° 52' 16'' S 47° 55' 7'' W 1066 m VFR Diurno/Noturno e IFR Diurno/Noturno
3 AAL 213 0 I KMIA SBBR 2017-01-23 01:20:00 2017-01-23 01:20:00 2017-01-23 09:00:00 2017-01-23 09:00:00 ... NaN NaN SBBR PRESIDENTE JUSCELINO KUBITSCHEK BRASÍLIA DF 15° 52' 16'' S 47° 55' 7'' W 1066 m VFR Diurno/Noturno e IFR Diurno/Noturno
4 AAL 213 0 I KMIA SBBR 2017-01-25 01:20:00 2017-01-25 01:20:00 2017-01-25 09:00:00 2017-01-25 09:00:00 ... NaN NaN SBBR PRESIDENTE JUSCELINO KUBITSCHEK BRASÍLIA DF 15° 52' 16'' S 47° 55' 7'' W 1066 m VFR Diurno/Noturno e IFR Diurno/Noturno

5 rows × 28 columns

--- Sandbox. Test area: Danger! Do Not Trepass Beyond This Point! --


In [22]:
dfFlights = flights[['airportA']]

In [23]:
dfAirports = airports[['airport']]

In [27]:
dfFlights.info()


<class 'pandas.core.frame.DataFrame'>
RangeIndex: 820958 entries, 0 to 820957
Data columns (total 1 columns):
airportA    820958 non-null object
dtypes: object(1)
memory usage: 6.3+ MB

In [28]:
dfAirports.info()


<class 'pandas.core.frame.DataFrame'>
RangeIndex: 589 entries, 0 to 588
Data columns (total 1 columns):
airport    589 non-null object
dtypes: object(1)
memory usage: 4.7+ KB

In [25]:
display('dfFlights', 'dfAirports', pd.merge(dfFlights, dfAirports, left_on="airportA", right_on="airport"))


'dfFlights'
'dfAirports'
airportA airport
0 SBBR SBBR
1 SBBR SBBR
2 SBBR SBBR
3 SBBR SBBR
4 SBBR SBBR
5 SBBR SBBR
6 SBBR SBBR
7 SBBR SBBR
8 SBBR SBBR
9 SBBR SBBR
10 SBBR SBBR
11 SBBR SBBR
12 SBBR SBBR
13 SBBR SBBR
14 SBBR SBBR
15 SBBR SBBR
16 SBBR SBBR
17 SBBR SBBR
18 SBBR SBBR
19 SBBR SBBR
20 SBBR SBBR
21 SBBR SBBR
22 SBBR SBBR
23 SBBR SBBR
24 SBBR SBBR
25 SBBR SBBR
26 SBBR SBBR
27 SBBR SBBR
28 SBBR SBBR
29 SBBR SBBR
... ... ...
722950 SBNM SBNM
722951 SBNM SBNM
722952 SBNM SBNM
722953 SBNM SBNM
722954 SBNM SBNM
722955 SBNM SBNM
722956 SBNM SBNM
722957 SBNM SBNM
722958 SBNM SBNM
722959 SBNM SBNM
722960 SBNM SBNM
722961 SBNM SBNM
722962 SBNM SBNM
722963 SBNM SBNM
722964 SBNM SBNM
722965 SBNM SBNM
722966 SBNM SBNM
722967 SBNM SBNM
722968 SBNM SBNM
722969 SBNM SBNM
722970 SBNM SBNM
722971 SBNM SBNM
722972 SBNM SBNM
722973 SBNM SBNM
722974 SBNM SBNM
722975 SBNM SBNM
722976 SBNM SBNM
722977 SBNM SBNM
722978 SBNM SBNM
722979 SBJD SBJD

722980 rows × 2 columns


In [35]:
# Not working: 
# pd.merge('dfFlights', 'dfAirports', pd.merge(dfFlights, dfAirports, left_on='airportA', right_on='airport'))
# ------------------------

In [40]:
# A more easy attempt
df1 = pd.DataFrame({'airportA': ['SBBH', 'SBCG', 'SBKP', 'KMIA', 'HONO'],
                    'airportB': ['SBBR', 'SBCT', 'SBAM', 'GERM', 'ENGL']},
                   columns=['airportA', 'airportB'])
df2 = pd.DataFrame({'airport': ['SBBH', 'SBCG', 'SBKP', 'SBBR', 'SBCT', 'SBAM'],
                    'state': ['MG', 'SP', 'SP', 'DF', 'PR', 'AM']},
                   columns=['airport', 'state'])

In [41]:
df1


Out[41]:
airportA airportB
0 SBBH SBBR
1 SBCG SBCT
2 SBKP SBAM
3 KMIA GERM
4 HONO ENGL

In [42]:
df2


Out[42]:
airport state
0 SBBH MG
1 SBCG SP
2 SBKP SP
3 SBBR DF
4 SBCT PR
5 SBAM AM

In [45]:
display('df1', 'df2', pd.merge(df1, df2, left_on="airportA", right_on="airport", how='left'))


'df1'
'df2'
airportA airportB airport state
0 SBBH SBBR SBBH MG
1 SBCG SBCT SBCG SP
2 SBKP SBAM SBKP SP
3 KMIA GERM NaN NaN
4 HONO ENGL NaN NaN

In [46]:
df3 = pd.merge(df1, df2, left_on="airportA", right_on="airport", how='left')

In [47]:
df3


Out[47]:
airportA airportB airport state
0 SBBH SBBR SBBH MG
1 SBCG SBCT SBCG SP
2 SBKP SBAM SBKP SP
3 KMIA GERM NaN NaN
4 HONO ENGL NaN NaN

In [48]:
display('df3', 'df2', pd.merge(df3, df2, left_on="airportB", right_on="airport", how='left'))


'df3'
'df2'
airportA airportB airport_x state_x airport_y state_y
0 SBBH SBBR SBBH MG SBBR DF
1 SBCG SBCT SBCG SP SBCT PR
2 SBKP SBAM SBKP SP SBAM AM
3 KMIA GERM NaN NaN NaN NaN
4 HONO ENGL NaN NaN NaN NaN

More tests...


In [49]:
sampleFlights = pd.read_csv('data/sampleFlights.csv', sep = ';', parse_dates = True)
sampleAirports = pd.read_csv('data/sampleAirports.csv', sep = ';', parse_dates = True)

In [50]:
sampleFlights.head()


Out[50]:
airline flightcode authcode linecode airportA airportB departureest departurereal arrivalest arrivalreal flightstatus problemcode
0 AAL 213 0 I KMIA SBBR 2017-01-30 01:20:00 2017-01-30 01:20:00 2017-01-30 09:00:00 2017-01-30 09:00:00 REALIZADO NaN
1 AAL 214 0 I SBBR KMIA 2017-01-05 23:55:00 2017-01-05 23:55:00 2017-01-06 07:45:00 2017-01-06 07:45:00 REALIZADO NaN
2 AAL 215 0 I KLAX SBGR 2017-01-21 21:55:00 2017-01-21 21:55:00 2017-01-22 10:00:00 2017-01-22 10:00:00 REALIZADO NaN
3 AAL 216 0 I SBGR KLAX 2017-01-15 00:05:00 2017-01-15 00:05:00 2017-01-15 12:35:00 2017-01-15 12:35:00 REALIZADO NaN
4 AAL 900 0 I SAEZ KMIA 2017-01-03 22:00:00 2017-01-03 22:00:00 2017-01-04 07:17:00 2017-01-04 07:17:00 REALIZADO NaN

In [51]:
sampleAirports.head()


Out[51]:
airport airportname city state latitude longitude altitude operation
0 SBBR PRESIDENTE JUSCELINO KUBITSCHEK BRASÍLIA DF 15° 52' 16'' S 47° 55' 7'' W 1066 m VFR Diurno/Noturno e IFR Diurno/Noturno
1 SBGR GUARULHOS - GOVERNADOR ANDRÉ FRANCO MONTORO GUARULHOS SP 23° 26' 8'' S 46° 28' 23'' W 750 m VFR Diurno/Noturno e IFR Diurno/Noturno
2 SBGL AEROPORTO INTERNACIONAL DO RIO DE JANEIRO/GALE... RIO DE JANEIRO RJ 22° 48' 36'' S 43° 15' 2'' W 9 m VFR Diurno/Noturno e IFR Diurno/Noturno
3 SBSP CONGONHAS SÃO PAULO SP 23° 37' 34'' S 46° 39' 23'' W 802 m VFR Diurno/Noturno e IFR Diurno/Noturno
4 SBRJ SANTOS DUMONT RIO DE JANEIRO RJ 22° 54' 36'' S 43° 9' 45'' W 3 m VFR Diurno/Noturno e IFR Diurno/Noturno

In [52]:
display('sampleFlights', 'sampleAirports', 
        pd.merge(sampleFlights, sampleAirports, left_on="airportA", right_on="airport", how='left'))


'sampleFlights'
'sampleAirports'
airline flightcode authcode linecode airportA airportB departureest departurereal arrivalest arrivalreal flightstatus problemcode airport airportname city state latitude longitude altitude operation
0 AAL 213 0 I KMIA SBBR 2017-01-30 01:20:00 2017-01-30 01:20:00 2017-01-30 09:00:00 2017-01-30 09:00:00 REALIZADO NaN NaN NaN NaN NaN NaN NaN NaN NaN
1 AAL 214 0 I SBBR KMIA 2017-01-05 23:55:00 2017-01-05 23:55:00 2017-01-06 07:45:00 2017-01-06 07:45:00 REALIZADO NaN SBBR PRESIDENTE JUSCELINO KUBITSCHEK BRASÍLIA DF 15° 52' 16'' S 47° 55' 7'' W 1066 m VFR Diurno/Noturno e IFR Diurno/Noturno
2 AAL 215 0 I KLAX SBGR 2017-01-21 21:55:00 2017-01-21 21:55:00 2017-01-22 10:00:00 2017-01-22 10:00:00 REALIZADO NaN NaN NaN NaN NaN NaN NaN NaN NaN
3 AAL 216 0 I SBGR KLAX 2017-01-15 00:05:00 2017-01-15 00:05:00 2017-01-15 12:35:00 2017-01-15 12:35:00 REALIZADO NaN SBGR GUARULHOS - GOVERNADOR ANDRÉ FRANCO MONTORO GUARULHOS SP 23° 26' 8'' S 46° 28' 23'' W 750 m VFR Diurno/Noturno e IFR Diurno/Noturno
4 AAL 900 0 I SAEZ KMIA 2017-01-03 22:00:00 2017-01-03 22:00:00 2017-01-04 07:17:00 2017-01-04 07:17:00 REALIZADO NaN NaN NaN NaN NaN NaN NaN NaN NaN
5 AAL 904 0 I SBGL KMIA 2017-01-03 22:40:00 2017-01-03 22:40:00 2017-01-04 07:35:00 2017-01-04 07:35:00 REALIZADO NaN SBGL AEROPORTO INTERNACIONAL DO RIO DE JANEIRO/GALE... RIO DE JANEIRO RJ 22° 48' 36'' S 43° 15' 2'' W 9 m VFR Diurno/Noturno e IFR Diurno/Noturno
6 AAL 953 0 I KJFK SAEZ 2017-01-21 00:59:00 2017-01-21 00:59:00 2017-01-21 11:41:00 2017-01-21 11:41:00 REALIZADO NaN NaN NaN NaN NaN NaN NaN NaN NaN
7 AAL 984 0 I SUMU KMIA 2017-01-11 22:40:00 2017-01-11 22:40:00 2017-01-12 08:07:00 2017-01-12 08:07:00 REALIZADO NaN NaN NaN NaN NaN NaN NaN NaN NaN
8 ACA 90 0 I CYYZ SBGR 2017-01-19 01:55:00 2017-01-19 01:55:00 2017-01-19 11:55:00 2017-01-19 11:32:00 REALIZADO MX NaN NaN NaN NaN NaN NaN NaN NaN
9 ONE 6176 0 N SBSP SBBR 2017-04-09 15:40:00 2017-04-09 15:32:00 2017-04-09 17:30:00 2017-04-09 17:03:00 REALIZADO NaN SBSP CONGONHAS SÃO PAULO SP 23° 37' 34'' S 46° 39' 23'' W 802 m VFR Diurno/Noturno e IFR Diurno/Noturno
10 AZU 2409 0 R SBRJ SBVT 2017-05-30 11:30:00 2017-05-30 11:30:00 2017-05-30 12:35:00 2017-05-30 12:35:00 REALIZADO NaN SBRJ SANTOS DUMONT RIO DE JANEIRO RJ 22° 54' 36'' S 43° 9' 45'' W 3 m VFR Diurno/Noturno e IFR Diurno/Noturno
11 AZU 2410 0 N SBGR SBCF 2017-05-20 06:00:00 2017-05-20 05:52:00 2017-05-20 07:20:00 2017-05-20 06:50:00 REALIZADO HD SBGR GUARULHOS - GOVERNADOR ANDRÉ FRANCO MONTORO GUARULHOS SP 23° 26' 8'' S 46° 28' 23'' W 750 m VFR Diurno/Noturno e IFR Diurno/Noturno
12 AZU 2415 0 N SBCF SBGR 2017-05-08 17:50:00 2017-05-08 17:48:00 2017-05-08 19:15:00 2017-05-08 19:04:00 REALIZADO HD SBCF TANCREDO NEVES CONFINS MG 19° 37' 26'' S 43° 58' 17'' W 827 m VFR Diurno/Noturno e IFR Diurno/Noturno
13 AZU 2407 0 N SBKP SBCT 2017-06-21 19:50:00 NaN 2017-06-21 20:50:00 NaN CANCELADO XB SBKP VIRACOPOS CAMPINAS SP 23° 0' 25'' S 47° 8' 4'' W 661 m VFR Diurno/Noturno e IFR Diurno/Noturno
14 AZU 9212 2 N SBKP SBLO NaN 2017-06-10 09:30:00 NaN 2017-06-10 11:06:00 REALIZADO NaN SBKP VIRACOPOS CAMPINAS SP 23° 0' 25'' S 47° 8' 4'' W 661 m VFR Diurno/Noturno e IFR Diurno/Noturno
15 AZU 9213 2 N SBLO SBKP NaN 2017-06-07 12:13:00 NaN 2017-06-07 13:36:00 REALIZADO NaN SBLO GOVERNADOR JOSÉ RICHA LONDRINA PR 23° 19' 49'' S 51° 8' 12'' W 569 m VFR Diurno/Noturno e IFR Diurno/Noturno
16 GLO 7612 2 I SBGL SACO NaN 2017-06-05 22:32:00 NaN 2017-06-06 02:37:00 REALIZADO NaN SBGL AEROPORTO INTERNACIONAL DO RIO DE JANEIRO/GALE... RIO DE JANEIRO RJ 22° 48' 36'' S 43° 15' 2'' W 9 m VFR Diurno/Noturno e IFR Diurno/Noturno
17 GLO 7617 0 I SAAR SBGL 2017-06-05 03:10:00 2017-06-05 03:10:00 2017-06-05 05:55:00 2017-06-05 05:55:00 REALIZADO NaN NaN NaN NaN NaN NaN NaN NaN NaN
18 TAM 3004 0 E SBCT SBSP 2017-06-01 08:23:00 2017-06-01 08:10:00 2017-06-01 09:20:00 2017-06-01 09:05:00 REALIZADO AT SBCT AFONSO PENA CURITIBA PR 25° 31' 54'' S 49° 10' 34'' W 911 m VFR Diurno/Noturno e IFR Diurno/Noturno

In [53]:
sampleMergeTemp = pd.merge(sampleFlights, sampleAirports, left_on="airportA", right_on="airport", how='left')

In [54]:
sampleMergeTemp


Out[54]:
airline flightcode authcode linecode airportA airportB departureest departurereal arrivalest arrivalreal flightstatus problemcode airport airportname city state latitude longitude altitude operation
0 AAL 213 0 I KMIA SBBR 2017-01-30 01:20:00 2017-01-30 01:20:00 2017-01-30 09:00:00 2017-01-30 09:00:00 REALIZADO NaN NaN NaN NaN NaN NaN NaN NaN NaN
1 AAL 214 0 I SBBR KMIA 2017-01-05 23:55:00 2017-01-05 23:55:00 2017-01-06 07:45:00 2017-01-06 07:45:00 REALIZADO NaN SBBR PRESIDENTE JUSCELINO KUBITSCHEK BRASÍLIA DF 15° 52' 16'' S 47° 55' 7'' W 1066 m VFR Diurno/Noturno e IFR Diurno/Noturno
2 AAL 215 0 I KLAX SBGR 2017-01-21 21:55:00 2017-01-21 21:55:00 2017-01-22 10:00:00 2017-01-22 10:00:00 REALIZADO NaN NaN NaN NaN NaN NaN NaN NaN NaN
3 AAL 216 0 I SBGR KLAX 2017-01-15 00:05:00 2017-01-15 00:05:00 2017-01-15 12:35:00 2017-01-15 12:35:00 REALIZADO NaN SBGR GUARULHOS - GOVERNADOR ANDRÉ FRANCO MONTORO GUARULHOS SP 23° 26' 8'' S 46° 28' 23'' W 750 m VFR Diurno/Noturno e IFR Diurno/Noturno
4 AAL 900 0 I SAEZ KMIA 2017-01-03 22:00:00 2017-01-03 22:00:00 2017-01-04 07:17:00 2017-01-04 07:17:00 REALIZADO NaN NaN NaN NaN NaN NaN NaN NaN NaN
5 AAL 904 0 I SBGL KMIA 2017-01-03 22:40:00 2017-01-03 22:40:00 2017-01-04 07:35:00 2017-01-04 07:35:00 REALIZADO NaN SBGL AEROPORTO INTERNACIONAL DO RIO DE JANEIRO/GALE... RIO DE JANEIRO RJ 22° 48' 36'' S 43° 15' 2'' W 9 m VFR Diurno/Noturno e IFR Diurno/Noturno
6 AAL 953 0 I KJFK SAEZ 2017-01-21 00:59:00 2017-01-21 00:59:00 2017-01-21 11:41:00 2017-01-21 11:41:00 REALIZADO NaN NaN NaN NaN NaN NaN NaN NaN NaN
7 AAL 984 0 I SUMU KMIA 2017-01-11 22:40:00 2017-01-11 22:40:00 2017-01-12 08:07:00 2017-01-12 08:07:00 REALIZADO NaN NaN NaN NaN NaN NaN NaN NaN NaN
8 ACA 90 0 I CYYZ SBGR 2017-01-19 01:55:00 2017-01-19 01:55:00 2017-01-19 11:55:00 2017-01-19 11:32:00 REALIZADO MX NaN NaN NaN NaN NaN NaN NaN NaN
9 ONE 6176 0 N SBSP SBBR 2017-04-09 15:40:00 2017-04-09 15:32:00 2017-04-09 17:30:00 2017-04-09 17:03:00 REALIZADO NaN SBSP CONGONHAS SÃO PAULO SP 23° 37' 34'' S 46° 39' 23'' W 802 m VFR Diurno/Noturno e IFR Diurno/Noturno
10 AZU 2409 0 R SBRJ SBVT 2017-05-30 11:30:00 2017-05-30 11:30:00 2017-05-30 12:35:00 2017-05-30 12:35:00 REALIZADO NaN SBRJ SANTOS DUMONT RIO DE JANEIRO RJ 22° 54' 36'' S 43° 9' 45'' W 3 m VFR Diurno/Noturno e IFR Diurno/Noturno
11 AZU 2410 0 N SBGR SBCF 2017-05-20 06:00:00 2017-05-20 05:52:00 2017-05-20 07:20:00 2017-05-20 06:50:00 REALIZADO HD SBGR GUARULHOS - GOVERNADOR ANDRÉ FRANCO MONTORO GUARULHOS SP 23° 26' 8'' S 46° 28' 23'' W 750 m VFR Diurno/Noturno e IFR Diurno/Noturno
12 AZU 2415 0 N SBCF SBGR 2017-05-08 17:50:00 2017-05-08 17:48:00 2017-05-08 19:15:00 2017-05-08 19:04:00 REALIZADO HD SBCF TANCREDO NEVES CONFINS MG 19° 37' 26'' S 43° 58' 17'' W 827 m VFR Diurno/Noturno e IFR Diurno/Noturno
13 AZU 2407 0 N SBKP SBCT 2017-06-21 19:50:00 NaN 2017-06-21 20:50:00 NaN CANCELADO XB SBKP VIRACOPOS CAMPINAS SP 23° 0' 25'' S 47° 8' 4'' W 661 m VFR Diurno/Noturno e IFR Diurno/Noturno
14 AZU 9212 2 N SBKP SBLO NaN 2017-06-10 09:30:00 NaN 2017-06-10 11:06:00 REALIZADO NaN SBKP VIRACOPOS CAMPINAS SP 23° 0' 25'' S 47° 8' 4'' W 661 m VFR Diurno/Noturno e IFR Diurno/Noturno
15 AZU 9213 2 N SBLO SBKP NaN 2017-06-07 12:13:00 NaN 2017-06-07 13:36:00 REALIZADO NaN SBLO GOVERNADOR JOSÉ RICHA LONDRINA PR 23° 19' 49'' S 51° 8' 12'' W 569 m VFR Diurno/Noturno e IFR Diurno/Noturno
16 GLO 7612 2 I SBGL SACO NaN 2017-06-05 22:32:00 NaN 2017-06-06 02:37:00 REALIZADO NaN SBGL AEROPORTO INTERNACIONAL DO RIO DE JANEIRO/GALE... RIO DE JANEIRO RJ 22° 48' 36'' S 43° 15' 2'' W 9 m VFR Diurno/Noturno e IFR Diurno/Noturno
17 GLO 7617 0 I SAAR SBGL 2017-06-05 03:10:00 2017-06-05 03:10:00 2017-06-05 05:55:00 2017-06-05 05:55:00 REALIZADO NaN NaN NaN NaN NaN NaN NaN NaN NaN
18 TAM 3004 0 E SBCT SBSP 2017-06-01 08:23:00 2017-06-01 08:10:00 2017-06-01 09:20:00 2017-06-01 09:05:00 REALIZADO AT SBCT AFONSO PENA CURITIBA PR 25° 31' 54'' S 49° 10' 34'' W 911 m VFR Diurno/Noturno e IFR Diurno/Noturno

In [56]:
display('sampleMergeTemp', 'sampleAirports', 
        pd.merge(sampleMergeTemp, sampleAirports, left_on="airportB", right_on="airport", how='left'))


'sampleMergeTemp'
'sampleAirports'
airline flightcode authcode linecode airportA airportB departureest departurereal arrivalest arrivalreal ... altitude_x operation_x airport_y airportname_y city_y state_y latitude_y longitude_y altitude_y operation_y
0 AAL 213 0 I KMIA SBBR 2017-01-30 01:20:00 2017-01-30 01:20:00 2017-01-30 09:00:00 2017-01-30 09:00:00 ... NaN NaN SBBR PRESIDENTE JUSCELINO KUBITSCHEK BRASÍLIA DF 15° 52' 16'' S 47° 55' 7'' W 1066 m VFR Diurno/Noturno e IFR Diurno/Noturno
1 AAL 214 0 I SBBR KMIA 2017-01-05 23:55:00 2017-01-05 23:55:00 2017-01-06 07:45:00 2017-01-06 07:45:00 ... 1066 m VFR Diurno/Noturno e IFR Diurno/Noturno NaN NaN NaN NaN NaN NaN NaN NaN
2 AAL 215 0 I KLAX SBGR 2017-01-21 21:55:00 2017-01-21 21:55:00 2017-01-22 10:00:00 2017-01-22 10:00:00 ... NaN NaN SBGR GUARULHOS - GOVERNADOR ANDRÉ FRANCO MONTORO GUARULHOS SP 23° 26' 8'' S 46° 28' 23'' W 750 m VFR Diurno/Noturno e IFR Diurno/Noturno
3 AAL 216 0 I SBGR KLAX 2017-01-15 00:05:00 2017-01-15 00:05:00 2017-01-15 12:35:00 2017-01-15 12:35:00 ... 750 m VFR Diurno/Noturno e IFR Diurno/Noturno NaN NaN NaN NaN NaN NaN NaN NaN
4 AAL 900 0 I SAEZ KMIA 2017-01-03 22:00:00 2017-01-03 22:00:00 2017-01-04 07:17:00 2017-01-04 07:17:00 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
5 AAL 904 0 I SBGL KMIA 2017-01-03 22:40:00 2017-01-03 22:40:00 2017-01-04 07:35:00 2017-01-04 07:35:00 ... 9 m VFR Diurno/Noturno e IFR Diurno/Noturno NaN NaN NaN NaN NaN NaN NaN NaN
6 AAL 953 0 I KJFK SAEZ 2017-01-21 00:59:00 2017-01-21 00:59:00 2017-01-21 11:41:00 2017-01-21 11:41:00 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
7 AAL 984 0 I SUMU KMIA 2017-01-11 22:40:00 2017-01-11 22:40:00 2017-01-12 08:07:00 2017-01-12 08:07:00 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
8 ACA 90 0 I CYYZ SBGR 2017-01-19 01:55:00 2017-01-19 01:55:00 2017-01-19 11:55:00 2017-01-19 11:32:00 ... NaN NaN SBGR GUARULHOS - GOVERNADOR ANDRÉ FRANCO MONTORO GUARULHOS SP 23° 26' 8'' S 46° 28' 23'' W 750 m VFR Diurno/Noturno e IFR Diurno/Noturno
9 ONE 6176 0 N SBSP SBBR 2017-04-09 15:40:00 2017-04-09 15:32:00 2017-04-09 17:30:00 2017-04-09 17:03:00 ... 802 m VFR Diurno/Noturno e IFR Diurno/Noturno SBBR PRESIDENTE JUSCELINO KUBITSCHEK BRASÍLIA DF 15° 52' 16'' S 47° 55' 7'' W 1066 m VFR Diurno/Noturno e IFR Diurno/Noturno
10 AZU 2409 0 R SBRJ SBVT 2017-05-30 11:30:00 2017-05-30 11:30:00 2017-05-30 12:35:00 2017-05-30 12:35:00 ... 3 m VFR Diurno/Noturno e IFR Diurno/Noturno NaN NaN NaN NaN NaN NaN NaN NaN
11 AZU 2410 0 N SBGR SBCF 2017-05-20 06:00:00 2017-05-20 05:52:00 2017-05-20 07:20:00 2017-05-20 06:50:00 ... 750 m VFR Diurno/Noturno e IFR Diurno/Noturno SBCF TANCREDO NEVES CONFINS MG 19° 37' 26'' S 43° 58' 17'' W 827 m VFR Diurno/Noturno e IFR Diurno/Noturno
12 AZU 2415 0 N SBCF SBGR 2017-05-08 17:50:00 2017-05-08 17:48:00 2017-05-08 19:15:00 2017-05-08 19:04:00 ... 827 m VFR Diurno/Noturno e IFR Diurno/Noturno SBGR GUARULHOS - GOVERNADOR ANDRÉ FRANCO MONTORO GUARULHOS SP 23° 26' 8'' S 46° 28' 23'' W 750 m VFR Diurno/Noturno e IFR Diurno/Noturno
13 AZU 2407 0 N SBKP SBCT 2017-06-21 19:50:00 NaN 2017-06-21 20:50:00 NaN ... 661 m VFR Diurno/Noturno e IFR Diurno/Noturno SBCT AFONSO PENA CURITIBA PR 25° 31' 54'' S 49° 10' 34'' W 911 m VFR Diurno/Noturno e IFR Diurno/Noturno
14 AZU 9212 2 N SBKP SBLO NaN 2017-06-10 09:30:00 NaN 2017-06-10 11:06:00 ... 661 m VFR Diurno/Noturno e IFR Diurno/Noturno SBLO GOVERNADOR JOSÉ RICHA LONDRINA PR 23° 19' 49'' S 51° 8' 12'' W 569 m VFR Diurno/Noturno e IFR Diurno/Noturno
15 AZU 9213 2 N SBLO SBKP NaN 2017-06-07 12:13:00 NaN 2017-06-07 13:36:00 ... 569 m VFR Diurno/Noturno e IFR Diurno/Noturno SBKP VIRACOPOS CAMPINAS SP 23° 0' 25'' S 47° 8' 4'' W 661 m VFR Diurno/Noturno e IFR Diurno/Noturno
16 GLO 7612 2 I SBGL SACO NaN 2017-06-05 22:32:00 NaN 2017-06-06 02:37:00 ... 9 m VFR Diurno/Noturno e IFR Diurno/Noturno NaN NaN NaN NaN NaN NaN NaN NaN
17 GLO 7617 0 I SAAR SBGL 2017-06-05 03:10:00 2017-06-05 03:10:00 2017-06-05 05:55:00 2017-06-05 05:55:00 ... NaN NaN SBGL AEROPORTO INTERNACIONAL DO RIO DE JANEIRO/GALE... RIO DE JANEIRO RJ 22° 48' 36'' S 43° 15' 2'' W 9 m VFR Diurno/Noturno e IFR Diurno/Noturno
18 TAM 3004 0 E SBCT SBSP 2017-06-01 08:23:00 2017-06-01 08:10:00 2017-06-01 09:20:00 2017-06-01 09:05:00 ... 911 m VFR Diurno/Noturno e IFR Diurno/Noturno SBSP CONGONHAS SÃO PAULO SP 23° 37' 34'' S 46° 39' 23'' W 802 m VFR Diurno/Noturno e IFR Diurno/Noturno

19 rows × 28 columns


In [57]:
sampleMergeFinal = pd.merge(sampleMergeTemp, sampleAirports, left_on="airportB", right_on="airport", how='left')

In [58]:
sampleMergeFinal


Out[58]:
airline flightcode authcode linecode airportA airportB departureest departurereal arrivalest arrivalreal ... altitude_x operation_x airport_y airportname_y city_y state_y latitude_y longitude_y altitude_y operation_y
0 AAL 213 0 I KMIA SBBR 2017-01-30 01:20:00 2017-01-30 01:20:00 2017-01-30 09:00:00 2017-01-30 09:00:00 ... NaN NaN SBBR PRESIDENTE JUSCELINO KUBITSCHEK BRASÍLIA DF 15° 52' 16'' S 47° 55' 7'' W 1066 m VFR Diurno/Noturno e IFR Diurno/Noturno
1 AAL 214 0 I SBBR KMIA 2017-01-05 23:55:00 2017-01-05 23:55:00 2017-01-06 07:45:00 2017-01-06 07:45:00 ... 1066 m VFR Diurno/Noturno e IFR Diurno/Noturno NaN NaN NaN NaN NaN NaN NaN NaN
2 AAL 215 0 I KLAX SBGR 2017-01-21 21:55:00 2017-01-21 21:55:00 2017-01-22 10:00:00 2017-01-22 10:00:00 ... NaN NaN SBGR GUARULHOS - GOVERNADOR ANDRÉ FRANCO MONTORO GUARULHOS SP 23° 26' 8'' S 46° 28' 23'' W 750 m VFR Diurno/Noturno e IFR Diurno/Noturno
3 AAL 216 0 I SBGR KLAX 2017-01-15 00:05:00 2017-01-15 00:05:00 2017-01-15 12:35:00 2017-01-15 12:35:00 ... 750 m VFR Diurno/Noturno e IFR Diurno/Noturno NaN NaN NaN NaN NaN NaN NaN NaN
4 AAL 900 0 I SAEZ KMIA 2017-01-03 22:00:00 2017-01-03 22:00:00 2017-01-04 07:17:00 2017-01-04 07:17:00 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
5 AAL 904 0 I SBGL KMIA 2017-01-03 22:40:00 2017-01-03 22:40:00 2017-01-04 07:35:00 2017-01-04 07:35:00 ... 9 m VFR Diurno/Noturno e IFR Diurno/Noturno NaN NaN NaN NaN NaN NaN NaN NaN
6 AAL 953 0 I KJFK SAEZ 2017-01-21 00:59:00 2017-01-21 00:59:00 2017-01-21 11:41:00 2017-01-21 11:41:00 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
7 AAL 984 0 I SUMU KMIA 2017-01-11 22:40:00 2017-01-11 22:40:00 2017-01-12 08:07:00 2017-01-12 08:07:00 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
8 ACA 90 0 I CYYZ SBGR 2017-01-19 01:55:00 2017-01-19 01:55:00 2017-01-19 11:55:00 2017-01-19 11:32:00 ... NaN NaN SBGR GUARULHOS - GOVERNADOR ANDRÉ FRANCO MONTORO GUARULHOS SP 23° 26' 8'' S 46° 28' 23'' W 750 m VFR Diurno/Noturno e IFR Diurno/Noturno
9 ONE 6176 0 N SBSP SBBR 2017-04-09 15:40:00 2017-04-09 15:32:00 2017-04-09 17:30:00 2017-04-09 17:03:00 ... 802 m VFR Diurno/Noturno e IFR Diurno/Noturno SBBR PRESIDENTE JUSCELINO KUBITSCHEK BRASÍLIA DF 15° 52' 16'' S 47° 55' 7'' W 1066 m VFR Diurno/Noturno e IFR Diurno/Noturno
10 AZU 2409 0 R SBRJ SBVT 2017-05-30 11:30:00 2017-05-30 11:30:00 2017-05-30 12:35:00 2017-05-30 12:35:00 ... 3 m VFR Diurno/Noturno e IFR Diurno/Noturno NaN NaN NaN NaN NaN NaN NaN NaN
11 AZU 2410 0 N SBGR SBCF 2017-05-20 06:00:00 2017-05-20 05:52:00 2017-05-20 07:20:00 2017-05-20 06:50:00 ... 750 m VFR Diurno/Noturno e IFR Diurno/Noturno SBCF TANCREDO NEVES CONFINS MG 19° 37' 26'' S 43° 58' 17'' W 827 m VFR Diurno/Noturno e IFR Diurno/Noturno
12 AZU 2415 0 N SBCF SBGR 2017-05-08 17:50:00 2017-05-08 17:48:00 2017-05-08 19:15:00 2017-05-08 19:04:00 ... 827 m VFR Diurno/Noturno e IFR Diurno/Noturno SBGR GUARULHOS - GOVERNADOR ANDRÉ FRANCO MONTORO GUARULHOS SP 23° 26' 8'' S 46° 28' 23'' W 750 m VFR Diurno/Noturno e IFR Diurno/Noturno
13 AZU 2407 0 N SBKP SBCT 2017-06-21 19:50:00 NaN 2017-06-21 20:50:00 NaN ... 661 m VFR Diurno/Noturno e IFR Diurno/Noturno SBCT AFONSO PENA CURITIBA PR 25° 31' 54'' S 49° 10' 34'' W 911 m VFR Diurno/Noturno e IFR Diurno/Noturno
14 AZU 9212 2 N SBKP SBLO NaN 2017-06-10 09:30:00 NaN 2017-06-10 11:06:00 ... 661 m VFR Diurno/Noturno e IFR Diurno/Noturno SBLO GOVERNADOR JOSÉ RICHA LONDRINA PR 23° 19' 49'' S 51° 8' 12'' W 569 m VFR Diurno/Noturno e IFR Diurno/Noturno
15 AZU 9213 2 N SBLO SBKP NaN 2017-06-07 12:13:00 NaN 2017-06-07 13:36:00 ... 569 m VFR Diurno/Noturno e IFR Diurno/Noturno SBKP VIRACOPOS CAMPINAS SP 23° 0' 25'' S 47° 8' 4'' W 661 m VFR Diurno/Noturno e IFR Diurno/Noturno
16 GLO 7612 2 I SBGL SACO NaN 2017-06-05 22:32:00 NaN 2017-06-06 02:37:00 ... 9 m VFR Diurno/Noturno e IFR Diurno/Noturno NaN NaN NaN NaN NaN NaN NaN NaN
17 GLO 7617 0 I SAAR SBGL 2017-06-05 03:10:00 2017-06-05 03:10:00 2017-06-05 05:55:00 2017-06-05 05:55:00 ... NaN NaN SBGL AEROPORTO INTERNACIONAL DO RIO DE JANEIRO/GALE... RIO DE JANEIRO RJ 22° 48' 36'' S 43° 15' 2'' W 9 m VFR Diurno/Noturno e IFR Diurno/Noturno
18 TAM 3004 0 E SBCT SBSP 2017-06-01 08:23:00 2017-06-01 08:10:00 2017-06-01 09:20:00 2017-06-01 09:05:00 ... 911 m VFR Diurno/Noturno e IFR Diurno/Noturno SBSP CONGONHAS SÃO PAULO SP 23° 37' 34'' S 46° 39' 23'' W 802 m VFR Diurno/Noturno e IFR Diurno/Noturno

19 rows × 28 columns


In [ ]: