In [23]:
import csv

# reader example
with open("foo.csv") as foo: 
    foo_reader = csv.reader(foo)
    
    # this is how you can grab the first header row out of a csv
    header_row = next(foo_reader)
    
    for row in foo_reader:
        print(row)
   
    
# writer example 
with open("foo_write.csv", "w") as foo:
    foo_writer = csv.writer(foo)
    foo_writer.writerow(("col val 1", "col val 2", "col val 3", "col val 4"))


---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-23-268df52449cd> in <module>()
      2 
      3 # reader example
----> 4 with open("foo.csv") as foo:
      5     foo_reader = csv.reader(foo)
      6 

FileNotFoundError: [Errno 2] No such file or directory: 'foo.csv'

In [24]:
import csv
    
# writer example 
with open('foo_write.csv', 'w') as foo:
    foo_writer = csv.writer(foo)
    foo_writer.writerow(('col val 1', 'col val 2', 'col val 3', 'col val 4'))
    foo_writer.writerow(('Whisky', 'Tango', 'Seven', 'Four'))

In [25]:
# reader example
with open('foo_write.csv') as foo: 
    foo_reader = csv.reader(foo)
    
    # this is how you can grab the first header row out of a csv
    header_row = next(foo_reader)
    
    for row in foo_reader:
        print(row)


[]
['Whisky', 'Tango', 'Seven', 'Four']
[]

In [26]:
def csv_coffee():
    with open("coffee.csv") as coffee_csv:
        my_reader = csv.reader(coffee_csv)

        for row in my_reader:
            print(row)

In [27]:
csv_coffee()


['Coffee', 'Water', 'Milk', 'Icecream']
['Espresso', 'No', 'No', 'No']
['Long Black', 'Yes', 'No', 'No']
['Flat White', 'No', 'Yes', 'No']
['Cappuccino', 'No', 'Yes - Frothy', 'No']
['Affogato', 'No', 'No', 'Yes']

In [28]:
import csv
f=open("coffee.csv")
for row in csv.reader(f):
    print(row)


['Coffee', 'Water', 'Milk', 'Icecream']
['Espresso', 'No', 'No', 'No']
['Long Black', 'Yes', 'No', 'No']
['Flat White', 'No', 'Yes', 'No']
['Cappuccino', 'No', 'Yes - Frothy', 'No']
['Affogato', 'No', 'No', 'Yes']

In [29]:
def csv_airport():
    with open("airports.csv") as airports_csv:
        airport_reader = csv.reader(airports_csv)
        airport_headers = next(airport_reader)
        print(airport_headers)

        for row in airport_reader:
            if row[3] == "Canada":
                print(row)

In [30]:
csv_airport()


['ID', ' Airport-Name', ' City', ' Country', ' IATA', ' ICAO', ' Latitude', ' Longitude', ' Altitude', ' Timezone', ' DST', ' Tz-Type', ' Source']
['21', 'Sault Ste Marie Airport', 'Sault Sainte Marie', 'Canada', 'YAM', 'CYAM', '46.48500061035156', '-84.5093994140625', '630', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['22', 'Winnipeg / St. Andrews Airport', 'Winnipeg', 'Canada', 'YAV', 'CYAV', '50.0564002991', '-97.03250122070001', '760', '-6', 'A', 'America/Winnipeg', 'airport', 'OurAirports']
['23', 'Halifax / CFB Shearwater Heliport', 'Halifax', 'Canada', 'YAW', 'CYAW', '44.6397018433', '-63.499401092499994', '144', '-4', 'A', 'America/Halifax', 'airport', 'OurAirports']
['24', 'St. Anthony Airport', 'St. Anthony', 'Canada', 'YAY', 'CYAY', '51.3918991089', '-56.083099365200006', '108', '-3.5', 'A', 'America/St_Johns', 'airport', 'OurAirports']
['25', 'Tofino / Long Beach Airport', 'Tofino', 'Canada', 'YAZ', 'CYAZ', '49.079833', '-125.775583', '80', '-8', 'A', 'America/Vancouver', 'airport', 'OurAirports']
['26', 'Kugaaruk Airport', 'Pelly Bay', 'Canada', 'YBB', 'CYBB', '68.534401', '-89.808098', '56', '-7', 'A', 'America/Edmonton', 'airport', 'OurAirports']
['27', 'Baie Comeau Airport', 'Baie Comeau', 'Canada', 'YBC', 'CYBC', '49.13249969482422', '-68.20439910888672', '71', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['28', 'CFB Bagotville', 'Bagotville', 'Canada', 'YBG', 'CYBG', '48.33060073852539', '-70.99639892578125', '522', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['29', 'Baker Lake Airport', 'Baker Lake', 'Canada', 'YBK', 'CYBK', '64.29889678960001', '-96.077796936', '59', '-6', 'A', 'America/Winnipeg', 'airport', 'OurAirports']
['30', 'Campbell River Airport', 'Campbell River', 'Canada', 'YBL', 'CYBL', '49.950801849365234', '-125.27100372314453', '346', '-8', 'A', 'America/Vancouver', 'airport', 'OurAirports']
['31', 'Brandon Municipal Airport', 'Brandon', 'Canada', 'YBR', 'CYBR', '49.91', '-99.951897', '1343', '-6', 'A', 'America/Winnipeg', 'airport', 'OurAirports']
['32', 'Cambridge Bay Airport', 'Cambridge Bay', 'Canada', 'YCB', 'CYCB', '69.1081008911', '-105.138000488', '90', '-7', 'A', 'America/Edmonton', 'airport', 'OurAirports']
['33', 'Nanaimo Airport', 'Nanaimo', 'Canada', 'YCD', 'CYCD', '49.054970224899996', '-123.869862556', '92', '-8', 'A', 'America/Vancouver', 'airport', 'OurAirports']
['34', 'Castlegar/West Kootenay Regional Airport', 'Castlegar', 'Canada', 'YCG', 'CYCG', '49.2963981628', '-117.632003784', '1624', '-8', 'A', 'America/Vancouver', 'airport', 'OurAirports']
['35', 'Miramichi Airport', 'Chatham', 'Canada', 'YCH', 'CYCH', '47.007801', '-65.449203', '108', '-4', 'A', 'America/Halifax', 'airport', 'OurAirports']
['36', 'Charlo Airport', 'Charlo', 'Canada', 'YCL', 'CYCL', '47.990799', '-66.330299', '132', '-4', 'A', 'America/Halifax', 'airport', 'OurAirports']
['37', 'Kugluktuk Airport', 'Coppermine', 'Canada', 'YCO', 'CYCO', '67.81670379639999', '-115.143997192', '74', '-7', 'A', 'America/Edmonton', 'airport', 'OurAirports']
['38', 'Coronation Airport', 'Coronation', 'Canada', 'YCT', 'CYCT', '52.0750007629', '-111.444999695', '2595', '-7', 'A', 'America/Edmonton', 'airport', 'OurAirports']
['39', 'Chilliwack Airport', 'Chilliwack', 'Canada', 'YCW', 'CYCW', '49.1528015137', '-121.939002991', '32', '-8', 'A', 'America/Vancouver', 'airport', 'OurAirports']
['40', 'Clyde River Airport', 'Clyde River', 'Canada', 'YCY', 'CYCY', '70.4860992432', '-68.5167007446', '87', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['41', 'Coral Harbour Airport', 'Coral Harbour', 'Canada', 'YZS', 'CYZS', '64.1932983398', '-83.3593978882', '210', '-5', 'A', 'America/Coral_Harbour', 'airport', 'OurAirports']
['42', 'Dawson City Airport', 'Dawson', 'Canada', 'YDA', 'CYDA', '64.04309844970703', '-139.1280059814453', '1215', '-8', 'A', 'America/Vancouver', 'airport', 'OurAirports']
['43', 'Burwash Airport', 'Burwash', 'Canada', 'YDB', 'CYDB', '61.37110137939453', '-139.04100036621094', '2647', '-8', 'A', 'America/Vancouver', 'airport', 'OurAirports']
['44', 'Princeton Airport', 'Princeton', 'Canada', 'YDC', 'CYDC', '49.4681015015', '-120.511001587', '2298', '-8', 'A', 'America/Vancouver', 'airport', 'OurAirports']
['45', 'Deer Lake Airport', 'Deer Lake', 'Canada', 'YDF', 'CYDF', '49.21080017089844', '-57.39139938354492', '72', '-3.5', 'A', 'America/St_Johns', 'airport', 'OurAirports']
['46', 'Dease Lake Airport', 'Dease Lake', 'Canada', 'YDL', 'CYDL', '58.4221992493', '-130.031997681', '2600', '-8', 'A', 'America/Vancouver', 'airport', 'OurAirports']
['47', 'Dauphin Barker Airport', 'Dauphin', 'Canada', 'YDN', 'CYDN', '51.100799560546875', '-100.052001953125', '999', '-6', 'A', 'America/Winnipeg', 'airport', 'OurAirports']
['48', 'Dawson Creek Airport', 'Dawson Creek', 'Canada', 'YDQ', 'CYDQ', '55.7422981262207', '-120.18299865722656', '2148', '-7', 'A', 'America/Dawson_Creek', 'airport', 'OurAirports']
['49', 'Edmonton International Airport', 'Edmonton', 'Canada', 'YEG', 'CYEG', '53.309700012200004', '-113.580001831', '2373', '-7', 'A', 'America/Edmonton', 'airport', 'OurAirports']
['50', 'Arviat Airport', 'Eskimo Point', 'Canada', 'YEK', 'CYEK', '61.0942001343', '-94.07080078119999', '32', '-6', 'A', 'America/Winnipeg', 'airport', 'OurAirports']
['51', 'Estevan Airport', 'Estevan', 'Canada', 'YEN', 'CYEN', '49.2103004456', '-102.966003418', '1905', '-6', 'N', 'America/Regina', 'airport', 'OurAirports']
['52', 'Edson Airport', 'Edson', 'Canada', 'YET', 'CYET', '53.578899383499994', '-116.464996338', '3043', '-7', 'A', 'America/Edmonton', 'airport', 'OurAirports']
['53', 'Eureka Airport', 'Eureka', 'Canada', 'YEU', 'CYEU', '79.9946975708', '-85.814201355', '256', '-6', 'A', 'America/Winnipeg', 'airport', 'OurAirports']
['54', 'Inuvik Mike Zubko Airport', 'Inuvik', 'Canada', 'YEV', 'CYEV', '68.30419921880001', '-133.483001709', '224', '-7', 'A', 'America/Edmonton', 'airport', 'OurAirports']
['55', 'Iqaluit Airport', 'Iqaluit', 'Canada', 'YFB', 'CYFB', '63.756401062', '-68.5558013916', '110', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['56', 'Fredericton Airport', 'Fredericton', 'Canada', 'YFC', 'CYFC', '45.868900299072266', '-66.53720092773438', '68', '-4', 'A', 'America/Halifax', 'airport', 'OurAirports']
['57', 'Forestville Airport', 'Forestville', 'Canada', '\\N', 'CYFE', '48.74610137939453', '-69.09719848632812', '293', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['58', 'Flin Flon Airport', 'Flin Flon', 'Canada', 'YFO', 'CYFO', '54.6781005859375', '-101.68199920654297', '997', '-6', 'A', 'America/Winnipeg', 'airport', 'OurAirports']
['59', 'Fort Resolution Airport', 'Fort Resolution', 'Canada', 'YFR', 'CYFR', '61.1808013916', '-113.690002441', '526', '-7', 'A', 'America/Edmonton', 'airport', 'OurAirports']
['60', 'Fort Simpson Airport', 'Fort Simpson', 'Canada', 'YFS', 'CYFS', '61.76020050048828', '-121.23699951171875', '555', '-7', 'A', 'America/Edmonton', 'airport', 'OurAirports']
['61', 'Kingston Norman Rogers Airport', 'Kingston', 'Canada', 'YGK', 'CYGK', '44.22529983520508', '-76.5969009399414', '305', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['62', 'La Grande Rivière Airport', 'La Grande Riviere', 'Canada', 'YGL', 'CYGL', '53.625301361083984', '-77.7042007446289', '639', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['63', 'Gaspé (Michel-Pouliot) Airport', 'Gaspe', 'Canada', 'YGP', 'CYGP', '48.7752990723', '-64.4785995483', '112', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['64', 'Geraldton Greenstone Regional Airport', 'Geraldton', 'Canada', 'YGQ', 'CYGQ', '49.77830123901367', '-86.93939971923828', '1144', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['65', 'ÃŽles-de-la-Madeleine Airport', 'Iles De La Madeleine', 'Canada', 'YGR', 'CYGR', '47.42470169067383', '-61.778099060058594', '35', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['66', 'Hudson Bay Airport', 'Hudson Bay', 'Canada', 'YHB', 'CYHB', '52.8166999817', '-102.310997009', '1175', '-6', 'N', 'America/Regina', 'airport', 'OurAirports']
['67', 'Dryden Regional Airport', 'Dryden', 'Canada', 'YHD', 'CYHD', '49.83169937133789', '-92.74420166015625', '1354', '-6', 'A', 'America/Winnipeg', 'airport', 'OurAirports']
['68', 'Ulukhaktok Holman Airport', 'Holman Island', 'Canada', 'YHI', 'CYHI', '70.76280212402344', '-117.80599975585938', '117', '-7', 'A', 'America/Edmonton', 'airport', 'OurAirports']
['69', 'Gjoa Haven Airport', 'Gjoa Haven', 'Canada', 'YHK', 'CYHK', '68.635597229', '-95.84970092770001', '152', '-7', 'A', 'America/Edmonton', 'airport', 'OurAirports']
['70', 'John C. Munro Hamilton International Airport', 'Hamilton', 'Canada', 'YHM', 'CYHM', '43.173599243199995', '-79.93499755859999', '780', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['71', 'Montréal / Saint-Hubert Airport', 'Montreal', 'Canada', 'YHU', 'CYHU', '45.5175018311', '-73.4169006348', '90', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['72', 'Hay River / Merlyn Carter Airport', 'Hay River', 'Canada', 'YHY', 'CYHY', '60.8396987915', '-115.782997131', '541', '-7', 'A', 'America/Edmonton', 'airport', 'OurAirports']
['73', 'Halifax / Stanfield International Airport', 'Halifax', 'Canada', 'YHZ', 'CYHZ', '44.8807983398', '-63.5085983276', '477', '-4', 'A', 'America/Halifax', 'airport', 'OurAirports']
['74', 'Atikokan Municipal Airport', 'Atikokan', 'Canada', 'YIB', 'CYIB', '48.7738990784', '-91.6386032104', '1408', '-5', 'A', 'America/Coral_Harbour', 'airport', 'OurAirports']
['75', 'Pond Inlet Airport', 'Pond Inlet', 'Canada', 'YIO', 'CYIO', '72.6832962036', '-77.9666976929', '181', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['76', 'St Jean Airport', 'St. Jean', 'Canada', 'YJN', 'CYJN', '45.29439926147461', '-73.28109741210938', '136', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['77', 'Stephenville Airport', 'Stephenville', 'Canada', 'YJT', 'CYJT', '48.5442008972168', '-58.54999923706055', '84', '-3.5', 'A', 'America/St_Johns', 'airport', 'OurAirports']
['78', 'Kamloops Airport', 'Kamloops', 'Canada', 'YKA', 'CYKA', '50.7022018433', '-120.444000244', '1133', '-8', 'A', 'America/Vancouver', 'airport', 'OurAirports']
['79', 'Waterloo Airport', 'Waterloo', 'Canada', 'YKF', 'CYKF', '43.460800170899994', '-80.3786010742', '1055', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['80', 'Schefferville Airport', 'Schefferville', 'Canada', 'YKL', 'CYKL', '54.805301666259766', '-66.8052978515625', '1709', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['81', 'Kindersley Airport', 'Kindersley', 'Canada', 'YKY', 'CYKY', '51.5175018311', '-109.180999756', '2277', '-6', 'N', 'America/Regina', 'airport', 'OurAirports']
['82', 'Buttonville Municipal Airport', 'Toronto', 'Canada', 'YKZ', 'CYKZ', '43.86220169067383', '-79.37000274658203', '650', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['83', 'Chapleau Airport', 'Chapleau', 'Canada', 'YLD', 'CYLD', '47.81999969482422', '-83.3467025756836', '1470', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['84', 'Meadow Lake Airport', 'Meadow Lake', 'Canada', 'YLJ', 'CYLJ', '54.125301361083984', '-108.52300262451172', '1576', '-6', 'N', 'America/Regina', 'airport', 'OurAirports']
['85', 'Lloydminster Airport', 'Lloydminster', 'Canada', 'YLL', 'CYLL', '53.309200286865234', '-110.072998046875', '2193', '-7', 'A', 'America/Edmonton', 'airport', 'OurAirports']
['86', 'Alert Airport', 'Alert', 'Canada', 'YLT', 'CYLT', '82.51779937740001', '-62.2806015015', '100', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['87', 'Kelowna International Airport', 'Kelowna', 'Canada', 'YLW', 'CYLW', '49.9561004639', '-119.377998352', '1421', '-8', 'A', 'America/Vancouver', 'airport', 'OurAirports']
['88', 'Mayo Airport', 'Mayo', 'Canada', 'YMA', 'CYMA', '63.61640167236328', '-135.8679962158203', '1653', '-8', 'A', 'America/Vancouver', 'airport', 'OurAirports']
['89', 'Moose Jaw Air Vice Marshal C. M. McEwen Airport', 'Moose Jaw', 'Canada', 'YMJ', 'CYMJ', '50.330299377441406', '-105.55899810791016', '1892', '-6', 'N', 'America/Regina', 'airport', 'OurAirports']
['90', 'Fort McMurray Airport', 'Fort Mcmurray', 'Canada', 'YMM', 'CYMM', '56.653301239', '-111.222000122', '1211', '-7', 'A', 'America/Edmonton', 'airport', 'OurAirports']
['91', 'Moosonee Airport', 'Moosonee', 'Canada', 'YMO', 'CYMO', '51.291099548339844', '-80.60780334472656', '30', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['92', 'Maniwaki Airport', 'Maniwaki', 'Canada', 'YMW', 'CYMW', '46.2728004456', '-75.9906005859', '656', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['93', 'Montreal International (Mirabel) Airport', 'Montreal', 'Canada', 'YMX', 'CYMX', '45.6795005798', '-74.0386962891', '270', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['94', 'Natashquan Airport', 'Natashquan', 'Canada', 'YNA', 'CYNA', '50.189998626708984', '-61.78919982910156', '39', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['95', 'Ottawa / Gatineau Airport', 'Gatineau', 'Canada', 'YND', 'CYND', '45.521701812699995', '-75.5635986328', '211', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['96', 'Matagami Airport', 'Matagami', 'Canada', 'YNM', 'CYNM', '49.76169967651367', '-77.80280303955078', '918', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['97', 'Old Crow Airport', 'Old Crow', 'Canada', 'YOC', 'CYOC', '67.57060241699219', '-139.83900451660156', '824', '-8', 'A', 'America/Vancouver', 'airport', 'OurAirports']
['98', 'CFB Cold Lake', 'Cold Lake', 'Canada', 'YOD', 'CYOD', '54.404998779296875', '-110.27899932861328', '1775', '-7', 'A', 'America/Edmonton', 'airport', 'OurAirports']
['99', 'High Level Airport', 'High Level', 'Canada', 'YOJ', 'CYOJ', '58.62139892578125', '-117.16500091552734', '1110', '-7', 'A', 'America/Edmonton', 'airport', 'OurAirports']
['100', 'Ottawa Macdonald-Cartier International Airport', 'Ottawa', 'Canada', 'YOW', 'CYOW', '45.3224983215332', '-75.66919708251953', '374', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['101', 'Prince Albert Glass Field', 'Prince Albert', 'Canada', 'YPA', 'CYPA', '53.214199066199996', '-105.672996521', '1405', '-6', 'N', 'America/Regina', 'airport', 'OurAirports']
['102', 'Peace River Airport', 'Peace River', 'Canada', 'YPE', 'CYPE', '56.226898193359375', '-117.4469985961914', '1873', '-7', 'A', 'America/Edmonton', 'airport', 'OurAirports']
['103', 'Southport Airport', 'Portage-la-prairie', 'Canada', 'YPG', 'CYPG', '49.903099', '-98.273817', '885', '-6', 'A', 'America/Winnipeg', 'airport', 'OurAirports']
['104', 'Pitt Meadows Airport', 'Pitt Meadows', 'Canada', '\\N', 'CYPK', '49.21609878540039', '-122.70999908447266', '11', '-8', 'A', 'America/Vancouver', 'airport', 'OurAirports']
['105', 'Pickle Lake Airport', 'Pickle Lake', 'Canada', 'YPL', 'CYPL', '51.4463996887207', '-90.21420288085938', '1267', '-5', 'A', 'America/Coral_Harbour', 'airport', 'OurAirports']
['106', 'Port Menier Airport', 'Port Menier', 'Canada', 'YPN', 'CYPN', '49.83639907836914', '-64.2885971069336', '167', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['107', 'Peterborough Airport', 'Peterborough', 'Canada', 'YPQ', 'CYPQ', '44.22999954223633', '-78.36329650878906', '628', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['108', 'Prince Rupert Airport', 'Prince Pupert', 'Canada', 'YPR', 'CYPR', '54.286098480199996', '-130.445007324', '116', '-8', 'A', 'America/Vancouver', 'airport', 'OurAirports']
['109', 'Fort Chipewyan Airport', 'Fort Chipewyan', 'Canada', 'YPY', 'CYPY', '58.7672004699707', '-111.11699676513672', '761', '-7', 'A', 'America/Edmonton', 'airport', 'OurAirports']
['110', 'Muskoka Airport', 'Muskoka', 'Canada', 'YQA', 'CYQA', '44.974700927734375', '-79.30329895019531', '925', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['111', 'Quebec Jean Lesage International Airport', 'Quebec', 'Canada', 'YQB', 'CYQB', '46.7911', '-71.393303', '244', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['112', 'Red Deer Regional Airport', 'Red Deer Industrial', 'Canada', 'YQF', 'CYQF', '52.18220138549805', '-113.89399719238281', '2968', '-7', 'A', 'America/Edmonton', 'airport', 'OurAirports']
['113', 'Windsor Airport', 'Windsor', 'Canada', 'YQG', 'CYQG', '42.27560043334961', '-82.95559692382812', '622', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['114', 'Watson Lake Airport', 'Watson Lake', 'Canada', 'YQH', 'CYQH', '60.11640167236328', '-128.82200622558594', '2255', '-8', 'A', 'America/Vancouver', 'airport', 'OurAirports']
['115', 'Kenora Airport', 'Kenora', 'Canada', 'YQK', 'CYQK', '49.788299560546875', '-94.36309814453125', '1332', '-6', 'A', 'America/Winnipeg', 'airport', 'OurAirports']
['116', 'Lethbridge County Airport', 'Lethbridge', 'Canada', 'YQL', 'CYQL', '49.6302986145', '-112.800003052', '3048', '-7', 'A', 'America/Edmonton', 'airport', 'OurAirports']
['117', 'Greater Moncton International Airport', 'Moncton', 'Canada', 'YQM', 'CYQM', '46.11220169067383', '-64.67859649658203', '232', '-4', 'A', 'America/Halifax', 'airport', 'OurAirports']
['119', 'Comox Airport', 'Comox', 'Canada', 'YQQ', 'CYQQ', '49.71080017089844', '-124.88700103759766', '84', '-8', 'A', 'America/Vancouver', 'airport', 'OurAirports']
['120', 'Regina International Airport', 'Regina', 'Canada', 'YQR', 'CYQR', '50.43190002441406', '-104.66600036621094', '1894', '-6', 'N', 'America/Regina', 'airport', 'OurAirports']
['121', 'Thunder Bay Airport', 'Thunder Bay', 'Canada', 'YQT', 'CYQT', '48.37189865112305', '-89.32389831542969', '653', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['122', 'Grande Prairie Airport', 'Grande Prairie', 'Canada', 'YQU', 'CYQU', '55.1796989441', '-118.885002136', '2195', '-7', 'A', 'America/Edmonton', 'airport', 'OurAirports']
['123', 'Yorkton Municipal Airport', 'Yorkton', 'Canada', 'YQV', 'CYQV', '51.26470184326172', '-102.46199798583984', '1635', '-6', 'N', 'America/Regina', 'airport', 'OurAirports']
['124', 'North Battleford Airport', 'North Battleford', 'Canada', 'YQW', 'CYQW', '52.76919937133789', '-108.24400329589844', '1799', '-6', 'N', 'America/Regina', 'airport', 'OurAirports']
['125', 'Gander International Airport', 'Gander', 'Canada', 'YQX', 'CYQX', '48.9369010925293', '-54.56809997558594', '496', '-3.5', 'A', 'America/St_Johns', 'airport', 'OurAirports']
['126', 'Sydney / J.A. Douglas McCurdy Airport', 'Sydney', 'Canada', 'YQY', 'CYQY', '46.161399841299996', '-60.0477981567', '203', '-4', 'A', 'America/Halifax', 'airport', 'OurAirports']
['127', 'Quesnel Airport', 'Quesnel', 'Canada', 'YQZ', 'CYQZ', '53.026100158691406', '-122.51000213623047', '1789', '-8', 'A', 'America/Vancouver', 'airport', 'OurAirports']
['128', 'Resolute Bay Airport', 'Resolute', 'Canada', 'YRB', 'CYRB', '74.7169036865', '-94.9693984985', '215', '-6', 'A', 'America/Winnipeg', 'airport', 'OurAirports']
['129', 'Rivière-du-Loup Airport', 'Riviere Du Loup', 'Canada', 'YRI', 'CYRI', '47.764400482177734', '-69.58470153808594', '427', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['130', 'Roberval Airport', 'Roberval', 'Canada', 'YRJ', 'CYRJ', '48.52000045776367', '-72.2656021118164', '586', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['131', 'Rocky Mountain House Airport', 'Rocky Mountain House', 'Canada', 'YRM', 'CYRM', '52.4296989441', '-114.903999329', '3244', '-7', 'A', 'America/Edmonton', 'airport', 'OurAirports']
['132', 'Rankin Inlet Airport', 'Rankin Inlet', 'Canada', 'YRT', 'CYRT', '62.8114013672', '-92.1157989502', '94', '-6', 'A', 'America/Winnipeg', 'airport', 'OurAirports']
['133', 'Sudbury Airport', 'Sudbury', 'Canada', 'YSB', 'CYSB', '46.625', '-80.79889678955078', '1141', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['134', 'Sherbrooke Airport', 'Sherbrooke', 'Canada', 'YSC', 'CYSC', '45.4385986328125', '-71.69139862060547', '792', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['135', 'Saint John Airport', 'St. John', 'Canada', 'YSJ', 'CYSJ', '45.31610107421875', '-65.89029693603516', '357', '-4', 'A', 'America/Halifax', 'airport', 'OurAirports']
['136', 'Fort Smith Airport', 'Fort Smith', 'Canada', 'YSM', 'CYSM', '60.020301818847656', '-111.96199798583984', '671', '-7', 'A', 'America/Edmonton', 'airport', 'OurAirports']
['137', 'Nanisivik Airport', 'Nanisivik', 'Canada', 'YSR', 'CYSR', '72.982201', '-84.613602', '2106', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['138', 'Summerside Airport', 'Summerside', 'Canada', 'YSU', 'CYSU', '46.44060134887695', '-63.83359909057617', '56', '-4', 'A', 'America/Halifax', 'airport', 'OurAirports']
['139', 'Sachs Harbour (David Nasogaluak Jr. Saaryuaq) Airport', 'Sachs Harbour', 'Canada', 'YSY', 'CYSY', '71.9938964844', '-125.242996216', '282', '-7', 'A', 'America/Edmonton', 'airport', 'OurAirports']
['140', 'Cape Dorset Airport', 'Cape Dorset', 'Canada', 'YTE', 'CYTE', '64.2300033569', '-76.5267028809', '164', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['141', 'Thompson Airport', 'Thompson', 'Canada', 'YTH', 'CYTH', '55.80110168457031', '-97.86419677734375', '729', '-6', 'A', 'America/Winnipeg', 'airport', 'OurAirports']
['142', 'CFB Trenton', 'Trenton', 'Canada', 'YTR', 'CYTR', '44.118900299072266', '-77.5280990600586', '283', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['143', 'Timmins/Victor M. Power', 'Timmins', 'Canada', 'YTS', 'CYTS', '48.569698333699996', '-81.376701355', '967', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['144', 'Billy Bishop Toronto City Centre Airport', 'Toronto', 'Canada', 'YTZ', 'CYTZ', '43.627499', '-79.396202', '252', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['145', 'Tuktoyaktuk Airport', 'Tuktoyaktuk', 'Canada', 'YUB', 'CYUB', '69.43329620361328', '-133.0260009765625', '15', '-7', 'A', 'America/Edmonton', 'airport', 'OurAirports']
['146', 'Montreal / Pierre Elliott Trudeau International Airport', 'Montreal', 'Canada', 'YUL', 'CYUL', '45.4706001282', '-73.7407989502', '118', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['147', 'Repulse Bay Airport', 'Repulse Bay', 'Canada', 'YUT', 'CYUT', '66.5214004517', '-86.22470092770001', '80', '-6', 'A', 'America/Winnipeg', 'airport', 'OurAirports']
['148', 'Hall Beach Airport', 'Hall Beach', 'Canada', 'YUX', 'CYUX', '68.77610015869999', '-81.2425', '30', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['149', 'Rouyn Noranda Airport', 'Rouyn', 'Canada', 'YUY', 'CYUY', '48.20610046386719', '-78.83560180664062', '988', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['150', 'La Ronge Airport', 'La Ronge', 'Canada', 'YVC', 'CYVC', '55.151401519800004', '-105.262001038', '1242', '-6', 'N', 'America/Regina', 'airport', 'OurAirports']
['151', 'Vermilion Airport', 'Vermillion', 'Canada', 'YVG', 'CYVG', '53.355800628699996', '-110.823997498', '2025', '-7', 'A', 'America/Edmonton', 'airport', 'OurAirports']
['152', 'Qikiqtarjuaq Airport', 'Broughton Island', 'Canada', 'YVM', 'CYVM', '67.5457992554', '-64.03140258789999', '21', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['153', "Val-d'Or Airport", "Val D'or", 'Canada', 'YVO', 'CYVO', '48.0532989502', '-77.7827987671', '1107', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['154', 'Kuujjuaq Airport', 'Quujjuaq', 'Canada', 'YVP', 'CYVP', '58.096099853515625', '-68.4269027709961', '129', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['155', 'Norman Wells Airport', 'Norman Wells', 'Canada', 'YVQ', 'CYVQ', '65.28160095214844', '-126.7979965209961', '238', '-7', 'A', 'America/Edmonton', 'airport', 'OurAirports']
['156', 'Vancouver International Airport', 'Vancouver', 'Canada', 'YVR', 'CYVR', '49.193901062', '-123.183998108', '14', '-8', 'A', 'America/Vancouver', 'airport', 'OurAirports']
['157', 'Buffalo Narrows Airport', 'Buffalo Narrows', 'Canada', 'YVT', 'CYVT', '55.8418998718', '-108.417999268', '1423', '-6', 'N', 'America/Regina', 'airport', 'OurAirports']
['158', 'Wiarton Airport', 'Wiarton', 'Canada', 'YVV', 'CYVV', '44.7458', '-81.107201', '729', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['159', 'Petawawa Airport', 'Petawawa', 'Canada', 'YWA', 'CYWA', '45.95220184326172', '-77.31919860839844', '427', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['160', 'Winnipeg / James Armstrong Richardson International Airport', 'Winnipeg', 'Canada', 'YWG', 'CYWG', '49.909999847399995', '-97.2398986816', '783', '-6', 'A', 'America/Winnipeg', 'airport', 'OurAirports']
['161', 'Wabush Airport', 'Wabush', 'Canada', 'YWK', 'CYWK', '52.92190170288086', '-66.8644027709961', '1808', '-4', 'A', 'America/Halifax', 'airport', 'OurAirports']
['162', 'Williams Lake Airport', 'Williams Lake', 'Canada', 'YWL', 'CYWL', '52.1831016541', '-122.054000854', '3085', '-8', 'A', 'America/Vancouver', 'airport', 'OurAirports']
['163', 'Wrigley Airport', 'Wrigley', 'Canada', 'YWY', 'CYWY', '63.20940017700195', '-123.43699645996094', '489', '-7', 'A', 'America/Edmonton', 'airport', 'OurAirports']
['164', 'Cranbrook/Canadian Rockies International Airport', 'Cranbrook', 'Canada', 'YXC', 'CYXC', '49.610801696777', '-115.78199768066', '3082', '-7', 'A', 'America/Edmonton', 'airport', 'OurAirports']
['165', 'Edmonton City Centre (Blatchford Field) Airport', 'Edmonton', 'Canada', 'YXD', 'CYXD', '53.5724983215', '-113.521003723', '2202', '-7', 'A', 'America/Edmonton', 'airport', 'OurAirports']
['166', 'Saskatoon John G. Diefenbaker International Airport', 'Saskatoon', 'Canada', 'YXE', 'CYXE', '52.170799255371094', '-106.69999694824219', '1653', '-6', 'N', 'America/Regina', 'airport', 'OurAirports']
['167', 'Medicine Hat Airport', 'Medicine Hat', 'Canada', 'YXH', 'CYXH', '50.01890182495117', '-110.72100067138672', '2352', '-7', 'A', 'America/Edmonton', 'airport', 'OurAirports']
['168', 'Fort St John Airport', 'Fort Saint John', 'Canada', 'YXJ', 'CYXJ', '56.23809814453125', '-120.73999786376953', '2280', '-7', 'A', 'America/Dawson_Creek', 'airport', 'OurAirports']
['169', 'Sioux Lookout Airport', 'Sioux Lookout', 'Canada', 'YXL', 'CYXL', '50.11389923095703', '-91.9052963256836', '1258', '-6', 'A', 'America/Winnipeg', 'airport', 'OurAirports']
['170', 'Pangnirtung Airport', 'Pangnirtung', 'Canada', 'YXP', 'CYXP', '66.1449966431', '-65.71360015869999', '75', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['171', 'Earlton (Timiskaming Regional) Airport', 'Earlton', 'Canada', 'YXR', 'CYXR', '47.697400654599996', '-79.8473453522', '800', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['172', 'Prince George Airport', 'Prince George', 'Canada', 'YXS', 'CYXS', '53.8894004822', '-122.679000854', '2267', '-8', 'A', 'America/Vancouver', 'airport', 'OurAirports']
['173', 'Northwest Regional Airport Terrace-Kitimat', 'Terrace', 'Canada', 'YXT', 'CYXT', '54.468498', '-128.576009', '713', '-8', 'A', 'America/Vancouver', 'airport', 'OurAirports']
['174', 'London Airport', 'London', 'Canada', 'YXU', 'CYXU', '43.035599', '-81.1539', '912', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['175', 'Abbotsford Airport', 'Abbotsford', 'Canada', 'YXX', 'CYXX', '49.025299072265625', '-122.36100006103516', '195', '-8', 'A', 'America/Vancouver', 'airport', 'OurAirports']
['176', 'Whitehorse / Erik Nielsen International Airport', 'Whitehorse', 'Canada', 'YXY', 'CYXY', '60.7095985413', '-135.067001343', '2317', '-8', 'A', 'America/Vancouver', 'airport', 'OurAirports']
['177', 'North Bay Airport', 'North Bay', 'Canada', 'YYB', 'CYYB', '46.36360168457031', '-79.42279815673828', '1215', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['178', 'Calgary International Airport', 'Calgary', 'Canada', 'YYC', 'CYYC', '51.113899231', '-114.019996643', '3557', '-7', 'A', 'America/Edmonton', 'airport', 'OurAirports']
['179', 'Smithers Airport', 'Smithers', 'Canada', 'YYD', 'CYYD', '54.82469940185547', '-127.18299865722656', '1712', '-8', 'A', 'America/Vancouver', 'airport', 'OurAirports']
['180', 'Fort Nelson Airport', 'Fort Nelson', 'Canada', 'YYE', 'CYYE', '58.8363990784', '-122.597000122', '1253', '-8', 'A', 'America/Vancouver', 'airport', 'OurAirports']
['181', 'Penticton Airport', 'Penticton', 'Canada', 'YYF', 'CYYF', '49.46310043334961', '-119.60199737548828', '1129', '-8', 'A', 'America/Vancouver', 'airport', 'OurAirports']
['182', 'Charlottetown Airport', 'Charlottetown', 'Canada', 'YYG', 'CYYG', '46.290000915527344', '-63.12110137939453', '160', '-4', 'A', 'America/Halifax', 'airport', 'OurAirports']
['183', 'Taloyoak Airport', 'Spence Bay', 'Canada', 'YYH', 'CYYH', '69.5466995239', '-93.5766983032', '92', '-7', 'A', 'America/Edmonton', 'airport', 'OurAirports']
['184', 'Victoria International Airport', 'Victoria', 'Canada', 'YYJ', 'CYYJ', '48.646900177', '-123.426002502', '63', '-8', 'A', 'America/Vancouver', 'airport', 'OurAirports']
['185', 'Lynn Lake Airport', 'Lynn Lake', 'Canada', 'YYL', 'CYYL', '56.86389923095703', '-101.07599639892578', '1170', '-6', 'A', 'America/Winnipeg', 'airport', 'OurAirports']
['186', 'Swift Current Airport', 'Swift Current', 'Canada', 'YYN', 'CYYN', '50.291900634799994', '-107.691001892', '2680', '-6', 'N', 'America/Regina', 'airport', 'OurAirports']
['187', 'Churchill Airport', 'Churchill', 'Canada', 'YYQ', 'CYYQ', '58.739200592041016', '-94.06500244140625', '94', '-6', 'A', 'America/Winnipeg', 'airport', 'OurAirports']
['188', 'Goose Bay Airport', 'Goose Bay', 'Canada', 'YYR', 'CYYR', '53.3191986084', '-60.4258003235', '160', '-4', 'A', 'America/Halifax', 'airport', 'OurAirports']
['189', "St. John's International Airport", "St. John's", 'Canada', 'YYT', 'CYYT', '47.618598938', '-52.7518997192', '461', '-3.5', 'A', 'America/St_Johns', 'airport', 'OurAirports']
['190', 'Kapuskasing Airport', 'Kapuskasing', 'Canada', 'YYU', 'CYYU', '49.41389846801758', '-82.46749877929688', '743', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['191', 'Armstrong Airport', 'Armstrong', 'Canada', 'YYW', 'CYYW', '50.29029846191406', '-88.90969848632812', '1058', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['192', 'Mont Joli Airport', 'Mont Joli', 'Canada', 'YYY', 'CYYY', '48.60860061645508', '-68.20809936523438', '172', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['193', 'Lester B. Pearson International Airport', 'Toronto', 'Canada', 'YYZ', 'CYYZ', '43.6772003174', '-79.63059997559999', '569', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['194', 'Downsview Airport', 'Toronto', 'Canada', 'YZD', 'CYZD', '43.74250030517578', '-79.4655990600586', '652', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['195', 'Gore Bay Manitoulin Airport', 'Gore Bay', 'Canada', 'YZE', 'CYZE', '45.88529968261719', '-82.56780242919922', '635', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['196', 'Yellowknife Airport', 'Yellowknife', 'Canada', 'YZF', 'CYZF', '62.462799072265625', '-114.44000244140625', '675', '-7', 'A', 'America/Edmonton', 'airport', 'OurAirports']
['197', 'Slave Lake Airport', 'Slave Lake', 'Canada', 'YZH', 'CYZH', '55.2930984497', '-114.777000427', '1912', '-7', 'A', 'America/Edmonton', 'airport', 'OurAirports']
['198', 'Sandspit Airport', 'Sandspit', 'Canada', 'YZP', 'CYZP', '53.25429916379999', '-131.813995361', '21', '-8', 'A', 'America/Vancouver', 'airport', 'OurAirports']
['199', 'Chris Hadfield Airport', 'Sarnia', 'Canada', 'YZR', 'CYZR', '42.9994010925293', '-82.30889892578125', '594', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['200', 'Port Hardy Airport', 'Port Hardy', 'Canada', 'YZT', 'CYZT', '50.680599212646484', '-127.36699676513672', '71', '-8', 'A', 'America/Vancouver', 'airport', 'OurAirports']
['201', 'Whitecourt Airport', 'Whitecourt', 'Canada', 'YZU', 'CYZU', '54.14390182495117', '-115.78700256347656', '2567', '-7', 'A', 'America/Edmonton', 'airport', 'OurAirports']
['202', 'Sept-ÃŽles Airport', 'Sept-iles', 'Canada', 'YZV', 'CYZV', '50.22330093383789', '-66.2656021118164', '180', '-5', 'A', 'America/Toronto', 'airport', 'OurAirports']
['203', 'Teslin Airport', 'Teslin', 'Canada', 'YZW', 'CYZW', '60.17279815673828', '-132.7429962158203', '2313', '-8', 'A', 'America/Vancouver', 'airport', 'OurAirports']
['204', 'CFB Greenwood', 'Greenwood', 'Canada', 'YZX', 'CYZX', '44.98440170288086', '-64.91690063476562', '92', '-4', 'A', 'America/Halifax', 'airport', 'OurAirports']
['205', 'Faro Airport', 'Faro', 'Canada', 'ZFA', 'CZFA', '62.20750045776367', '-133.37600708007812', '2351', '-8', 'A', 'America/Vancouver', 'airport', 'OurAirports']
['206', 'Fort Mcpherson Airport', 'Fort Mcpherson', 'Canada', 'ZFM', 'CZFM', '67.40750122070312', '-134.86099243164062', '116', '-7', 'A', 'America/Edmonton', 'airport', 'OurAirports']
---------------------------------------------------------------------------
UnicodeDecodeError                        Traceback (most recent call last)
<ipython-input-30-d7144df7ae4a> in <module>()
----> 1 csv_airport()

<ipython-input-29-0199f64b9c9d> in csv_airport()
      5         print(airport_headers)
      6 
----> 7         for row in airport_reader:
      8             if row[3] == "Canada":
      9                 print(row)

~\AppData\Local\Programs\Python\Python36-32\lib\encodings\cp1252.py in decode(self, input, final)
     21 class IncrementalDecoder(codecs.IncrementalDecoder):
     22     def decode(self, input, final=False):
---> 23         return codecs.charmap_decode(input,self.errors,decoding_table)[0]
     24 
     25 class StreamWriter(Codec,codecs.StreamWriter):

UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 5569: character maps to <undefined>

In [31]:
def csv_airport(country):
    with open("airports.csv") as airports_csv:
        airport_reader = csv.reader(airports_csv)
        airport_headers = next(airport_reader)
        print(airport_headers)

        for row in airport_reader:
            if row[3] == country:
                print(row)

In [32]:
csv_airport('Germany')


['ID', ' Airport-Name', ' City', ' Country', ' IATA', ' ICAO', ' Latitude', ' Longitude', ' Altitude', ' Timezone', ' DST', ' Tz-Type', ' Source']
['317', 'Bautzen Airport', 'Bautzen', 'Germany', '\\N', 'EDAB', '51.19361114501953', '14.519721984863281', '568', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['318', 'Altenburg-Nobitz Airport', 'Altenburg', 'Germany', 'AOC', 'EDAC', '50.9819450378418', '12.506388664245605', '640', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['319', 'Dessau Airport', 'Dessau', 'Germany', '\\N', 'EDAD', '51.831693541', '12.1909618378', '187', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['320', 'Eisenhüttenstadt Airport', 'Eisenhuettenstadt', 'Germany', '\\N', 'EDAE', '52.195856', '14.58753', '144', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['322', 'Großenhain Airport', 'Suhl', 'Germany', '\\N', 'EDAK', '51.30805587768555', '13.555556297302246', '417', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['323', 'Merseburg Airport', 'Muehlhausen', 'Germany', '\\N', 'EDAM', '51.3630556', '11.9408333', '341', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['324', 'Halle-Oppin Airport', 'Halle', 'Germany', '\\N', 'EDAQ', '51.552223', '12.053889', '348', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['325', 'Riesa-Göhlis Airport', 'Riesa', 'Germany', '\\N', 'EDAU', '51.2936096191', '13.3561105728', '322', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['326', 'Rechlin-Lärz Airport', 'Rechlin-laerz', 'Germany', '\\N', 'EDAX', '53.306388855', '12.7522220612', '220', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['327', 'Strausberg Airport', 'Strausberg', 'Germany', '\\N', 'EDAY', '52.5805549621582', '13.916666984558105', '262', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['328', 'Schönhagen Airport', 'Schoenhagen', 'Germany', '\\N', 'EDAZ', '52.2036094666', '13.1563892365', '131', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['329', 'Barth Airport', 'Barth', 'Germany', 'BBH', 'EDBH', '54.338253', '12.710515', '23', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['330', 'Jena-Schöngleina Airport', 'Jena', 'Germany', '\\N', 'EDBJ', '50.915279388427734', '11.714444160461426', '1247', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['331', 'Kyritz Airport', 'Kyritz', 'Germany', '\\N', 'EDBK', '52.918888092041016', '12.425277709960938', '131', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['332', 'Magdeburg \\City\\" Airport"', 'Magdeburg', 'Germany', '\\N', 'EDBM', '52.073612', '11.626389', '259', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['333', 'Rothenburg/Görlitz Airport', 'Rothenburg/ol', 'Germany', '\\N', 'EDBR', '51.36333465576172', '14.949999809265137', '518', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['334', 'Anklam Airport', 'Anklam', 'Germany', '\\N', 'EDCA', '53.83277893066406', '13.668610572814941', '16', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['335', 'Cottbus-Drewitz Airport', 'Cottbus', 'Germany', '\\N', 'EDCD', '51.889442', '14.531944', '272', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['336', 'Kamenz Airport', 'Kamenz', 'Germany', '\\N', 'EDCM', '51.29694366455078', '14.1274995803833', '495', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['337', 'Berlin-Schönefeld International Airport', 'Berlin', 'Germany', 'SXF', 'EDDB', '52.380001068115', '13.522500038147', '157', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['338', 'Dresden Airport', 'Dresden', 'Germany', 'DRS', 'EDDC', '51.1328010559082', '13.767200469970703', '755', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['339', 'Erfurt Airport', 'Erfurt', 'Germany', 'ERF', 'EDDE', '50.979801177978516', '10.958100318908691', '1036', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['340', 'Frankfurt am Main International Airport', 'Frankfurt', 'Germany', 'FRA', 'EDDF', '50.0333333', '8.5705556', '364', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['341', 'Münster Osnabrück Airport', 'Munster', 'Germany', 'FMO', 'EDDG', '52.134601593', '7.68483018875', '160', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['342', 'Hamburg Airport', 'Hamburg', 'Germany', 'HAM', 'EDDH', '53.630401611328', '9.9882297515869', '53', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['343', 'Berlin-Tempelhof International Airport', 'Berlin', 'Germany', 'THF', 'EDDI', '52.472999572753906', '13.403900146484375', '167', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['344', 'Cologne Bonn Airport', 'Cologne', 'Germany', 'CGN', 'EDDK', '50.8658981323', '7.1427397728', '302', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['345', 'Düsseldorf International Airport', 'Duesseldorf', 'Germany', 'DUS', 'EDDL', '51.28950119018555', '6.766779899597168', '147', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['346', 'Munich International Airport', 'Munich', 'Germany', 'MUC', 'EDDM', '48.353801727295', '11.786100387573', '1487', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['347', 'Nuremberg Airport', 'Nuernberg', 'Germany', 'NUE', 'EDDN', '49.498699', '11.0780556', '1046', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['348', 'Leipzig Halle Airport', 'Leipzig', 'Germany', 'LEJ', 'EDDP', '51.4238889', '12.2363889', '465', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['349', 'Saarbrücken Airport', 'Saarbruecken', 'Germany', 'SCN', 'EDDR', '49.214599609400004', '7.10950994492', '1058', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['350', 'Stuttgart Airport', 'Stuttgart', 'Germany', 'STR', 'EDDS', '48.689899444599995', '9.22196006775', '1276', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['351', 'Berlin-Tegel International Airport', 'Berlin', 'Germany', 'TXL', 'EDDT', '52.5597000122', '13.2876996994', '122', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['352', 'Hannover Airport', 'Hannover', 'Germany', 'HAJ', 'EDDV', '52.461101532', '9.685079574580001', '183', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['353', 'Bremen Airport', 'Bremen', 'Germany', 'BRE', 'EDDW', '53.0475006104', '8.78666973114', '14', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['354', 'Frankfurt-Egelsbach Airport', 'Egelsbach', 'Germany', 'QEF', 'EDFE', '49.959999084472656', '8.645833015441895', '384', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['355', 'Frankfurt-Hahn Airport', 'Hahn', 'Germany', 'HHN', 'EDFH', '49.948699951200005', '7.263889789579999', '1649', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['356', 'Mannheim-City Airport', 'Mannheim', 'Germany', 'MHG', 'EDFM', '49.47305679321289', '8.514166831970215', '308', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['357', 'Allendorf/Eder Airport', 'Allendorf', 'Germany', '\\N', 'EDFQ', '51.03499984741211', '8.680832862854004', '1158', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['358', 'Worms Airport', 'Worms', 'Germany', '\\N', 'EDFV', '49.606945', '8.368333', '295', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['359', 'Mainz-Finthen Airport', 'Mainz', 'Germany', '\\N', 'EDFZ', '49.967499', '8.147222', '525', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['360', 'Eisenach-Kindel Airport', 'Eisenach', 'Germany', '\\N', 'EDGE', '50.991604', '10.47973', '1112', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['361', 'Siegerland Airport', 'Siegerland', 'Germany', '\\N', 'EDGS', '50.707698822021484', '8.082969665527344', '1966', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['362', 'Hamburg-Finkenwerder Airport', 'Hamburg', 'Germany', 'XFW', 'EDHI', '53.5352783203125', '9.835556030273438', '23', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['363', 'Kiel-Holtenau Airport', 'Kiel', 'Germany', 'KEL', 'EDHK', '54.37944412231445', '10.145277976989746', '102', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['364', 'Lübeck Blankensee Airport', 'Luebeck', 'Germany', 'LBC', 'EDHL', '53.8054008484', '10.7192001343', '53', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['365', 'Flugplatz Dahlemer Binz', 'Dahlemer Binz', 'Germany', '\\N', 'EDKV', '50.405555725', '6.5288891792', '1896', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['366', 'Meinerzhagen Airport', 'Meinerzhagen', 'Germany', '\\N', 'EDKZ', '51.099998474121094', '7.599999904632568', '1549', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['367', 'Arnsberg-Menden Airport', 'Arnsberg', 'Germany', 'ZCA', 'EDLA', '51.483890533447266', '7.8983330726623535', '794', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['368', 'Essen Mulheim Airport', 'Essen', 'Germany', 'ESS', 'EDLE', '51.40230178833008', '6.9373297691345215', '424', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['369', 'Bielefeld Airport', 'Bielefeld', 'Germany', '\\N', 'EDLI', '51.9647216797', '8.544444084170001', '433', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['370', 'Mönchengladbach Airport', 'Moenchengladbach', 'Germany', 'MGL', 'EDLN', '51.23027801513672', '6.504444122314453', '125', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['371', 'Paderborn Lippstadt Airport', 'Paderborn', 'Germany', 'PAD', 'EDLP', '51.614101409899995', '8.616319656369999', '699', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['372', 'Stadtlohn-Vreden Airport', 'Stadtlohn', 'Germany', '\\N', 'EDLS', '51.99583435058594', '6.8405561447143555', '157', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['373', 'Dortmund Airport', 'Dortmund', 'Germany', 'DTM', 'EDLW', '51.51829910279999', '7.61223983765', '425', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['374', 'Augsburg Airport', 'Augsburg', 'Germany', 'AGB', 'EDMA', '48.425278', '10.931667', '1516', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['375', 'Biberach a.d. Riß Airport', 'Biberach', 'Germany', '\\N', 'EDMB', '48.11111068725586', '9.762778282165527', '1903', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['376', 'Eggenfelden Airport', 'Eggenfelden', 'Germany', '\\N', 'EDME', '48.39611053466797', '12.723610877990723', '1342', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['377', 'Mindelheim-Mattsies Airport', 'Mindelheim', 'Germany', '\\N', 'EDMN', '48.1069450378418', '10.524999618530273', '1857', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['378', 'Oberpfaffenhofen Airport', 'Oberpfaffenhofen', 'Germany', 'OBF', 'EDMO', '48.08140182495117', '11.283100128173828', '1947', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['379', 'Straubing Airport', 'Straubing', 'Germany', 'RBM', 'EDMS', '48.90083312988281', '12.516667366027832', '1047', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['380', 'Vilshofen Airport', 'Vilshofen', 'Germany', '\\N', 'EDMV', '48.6349983215332', '13.195555686950684', '991', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['381', 'Leutkirch-Unterzeil Airport', 'Leutkirch', 'Germany', '\\N', 'EDNL', '47.858890533447266', '10.014166831970215', '2100', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['382', 'Friedrichshafen Airport', 'Friedrichshafen', 'Germany', 'FDH', 'EDNY', '47.671298980699994', '9.51148986816', '1367', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['383', 'Schwerin Parchim Airport', 'Parchim', 'Germany', 'SZW', 'EDOP', '53.426998', '11.7834', '166', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['384', 'Stendal-Borstel Airport', 'Stendal', 'Germany', 'ZSN', 'EDOV', '52.62888717651367', '11.818611145019531', '184', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['385', 'Aalen-Heidenheim/Elchingen Airport', 'Aalen-heidenheim', 'Germany', '\\N', 'EDPA', '48.77777862548828', '10.264721870422363', '1916', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['386', 'Bayreuth Airport', 'Bayreuth', 'Germany', 'BYU', 'EDQD', '49.98500061035156', '11.640000343322754', '1601', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['387', 'Burg Feuerstein Airport', 'Burg Feuerstein', 'Germany', '\\N', 'EDQE', '49.794166564941', '11.133610725403', '1673', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['388', 'Hof-Plauen Airport', 'Hof', 'Germany', 'HOQ', 'EDQM', '50.288612365722656', '11.856389045715332', '1959', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['389', 'Haßfurt-Schweinfurt Airport', 'Hassfurt', 'Germany', '\\N', 'EDQT', '50.0180549621582', '10.529443740844727', '719', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['390', 'Koblenz-Winningen Airport', 'Koblenz', 'Germany', 'ZNV', 'EDRK', '50.325557708740234', '7.528611183166504', '640', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['391', 'Trier-Föhren Airport', 'Trier', 'Germany', 'ZQF', 'EDRT', '49.863887786865234', '6.787499904632568', '666', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['392', 'Speyer Airport', 'Speyer', 'Germany', 'ZQC', 'EDRY', '49.30472183227539', '8.45138931274414', '312', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['393', 'Zweibrücken Airport', 'Zweibruecken', 'Germany', 'ZQW', 'EDRZ', '49.20940017700195', '7.400559902191162', '1132', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['394', 'Donaueschingen-Villingen Airport', 'Donaueschingen', 'Germany', 'ZQL', 'EDTD', '47.97333145139999', '8.52222156525', '2231', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['395', 'Freiburg i. Br. Airport', 'Freiburg', 'Germany', '\\N', 'EDTF', '48.022777557400005', '7.83249998093', '801', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['396', 'Mengen-Hohentengen Airport', 'Mengen', 'Germany', '\\N', 'EDTM', '48.053890228271484', '9.372777938842773', '1818', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['397', 'Adolf Würth Airport', 'Schwaebisch Hall', 'Germany', '\\N', 'EDTY', '49.1183319092', '9.783888816829998', '1299', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['398', 'Finsterwalde/Schacksdorf Airport', 'Soest', 'Germany', '\\N', 'EDUS', '51.607498', '13.743611', '384', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['399', 'Braunschweig Wolfsburg Airport', 'Braunschweig', 'Germany', 'BWE', 'EDVE', '52.319199', '10.5561', '295', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['400', 'Kassel-Calden Airport', 'Kassel', 'Germany', 'KSF', 'EDVK', '51.417273', '9.384967', '820', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['401', 'Hildesheim Airport', 'Hildesheim', 'Germany', '\\N', 'EDVM', '52.18138885498047', '9.946389198303223', '292', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['402', 'Bremerhaven Airport', 'Bremerhaven', 'Germany', 'BRV', 'EDWB', '53.506943', '8.572778', '10', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['403', 'Emden Airport', 'Emden', 'Germany', 'EME', 'EDWE', '53.391109466552734', '7.227499961853027', '3', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['404', 'Leer-Papenburg Airport', 'Leer', 'Germany', '\\N', 'EDWF', '53.271942138671875', '7.441667079925537', '3', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['405', 'Wilhelmshaven-Mariensiel Airport', 'Wilhelmshaven', 'Germany', 'WVN', 'EDWI', '53.502220153808594', '8.05222225189209', '16', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['406', 'Borkum Airport', 'Borkum', 'Germany', 'BMK', 'EDWR', '53.5963897705', '6.70916700363', '3', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['407', 'Norderney Airport', 'Norderney', 'Germany', 'NRD', 'EDWY', '53.70694351196289', '7.230000019073486', '7', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['408', 'Flensburg-Schäferhaus Airport', 'Flensburg', 'Germany', 'FLF', 'EDXF', '54.77333450317383', '9.378889083862305', '131', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['409', 'Rendsburg-Schachtholm Airport', 'Rendsburg', 'Germany', '\\N', 'EDXR', '54.220001220703125', '9.599444389343262', '23', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
['410', 'Westerland Sylt Airport', 'Westerland', 'Germany', 'GWT', 'EDXW', '54.9132003784', '8.34047031403', '51', '1', 'E', 'Europe/Berlin', 'airport', 'OurAirports']
---------------------------------------------------------------------------
UnicodeDecodeError                        Traceback (most recent call last)
<ipython-input-32-ce398ff3ddfd> in <module>()
----> 1 csv_airport('Germany')

<ipython-input-31-6113cd2cb430> in csv_airport(country)
      5         print(airport_headers)
      6 
----> 7         for row in airport_reader:
      8             if row[3] == country:
      9                 print(row)

~\AppData\Local\Programs\Python\Python36-32\lib\encodings\cp1252.py in decode(self, input, final)
     21 class IncrementalDecoder(codecs.IncrementalDecoder):
     22     def decode(self, input, final=False):
---> 23         return codecs.charmap_decode(input,self.errors,decoding_table)[0]
     24 
     25 class StreamWriter(Codec,codecs.StreamWriter):

UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 5569: character maps to <undefined>

In [33]:
# Using the Haversine formula for geographic Great Circle Distance
# As per https://en.wikipedia.org/wiki/Haversine_formula

from math import cos,radians,sin,pow,asin,sqrt

def distance(lat1, long1, lat2, long2):
    radius = 6371 # radius of the earth in km, roughly https://en.wikipedia.org/wiki/Earth_radius

    # Lat,long are in degrees but we need radians
    lat1 = radians(lat1)
    lat2 = radians(lat2)
    long1 = radians(long1)
    long2 = radians(long2)

    dlat = lat2-lat1
    dlon = long2-long1

    a = pow(sin(dlat/2),2) + cos(lat1)*cos(lat2)*pow(sin(dlon/2),2)
    distance = 2 * radius * asin(sqrt(a))

    return distance

In [37]:
def calc_airport_distances():
    # define two empty dicts that will hold our lat/long info
    airport_lats = {}
    airport_longs = {}

    with open("airports.csv") as airports_csv:
        # setup reader and remove header
        airport_reader = csv.reader(airports_csv)
        airport_headers = next(airport_reader)

        for row in airport_reader:
            airport_lats[row[0]] = float(row[6])
            airport_longs[row[0]] = float(row[7])
            
    # now that we have lookup dicts for lat/long loop through the routes 
    with open("routes.csv") as routes_csv:
        route_reader = csv.reader(routes_csv)
        route_headers = next(route_reader)

        for row in route_reader:
            source_id = row[3]
            dest_id = row[5]

            # check to see if the ids for both airports are in the lookup dicts
            if source_id in airport_lats and dest_id in airport_lats:
                # use the lat/long dicts to get the coordinate info for each airport
                source_lat = airport_lats[source_id]
                source_long = airport_longs[source_id]
                dest_lat = airport_lats[dest_id]
                dest_long = airport_longs[dest_id]
                
                # make a variable that captures the output from the geo_distance function
                km_dist = geo_distance.distance(source_lat,
                                                source_long,
                                                dest_lat,
                                                dest_lat)

In [ ]: