#!/usr/bin/env python # coding: utf-8 # # My First Data Science Project # ## Helicopter Escapes # We begin by importing some helper functions. # In[1]: from helper import * # ## Get the Data # Now, let's get the data from the [List of helicopter prison escapes] Wikipedia article. # In[2]: url = "https://en.wikipedia.org/wiki/List_of_helicopter_prison_escapes" data = data_from_url(url) # Let's print the first three rows. # In[3]: for row in data[:3]: print(row) # # Removing the Details # We initialize a variable of index with a value of 0. The purpose of this valuable is to keep track of which row we are modifying. # In[6]: index = 0 for row in data: data[index] = row[:-1] index += 1 # In[7]: print(data[:3]) # # Extracting the Year # Using the helper function, fetch_year, we display only the year of the helicopter escapes. # In[8]: for row in data: row[0] = fetch_year(row[0]) # In[9]: print(data[0:3]) # Now, let's determine the min and max year in our data. # In[10]: min_year = min(data, key=lambda x: x[0])[0] max_year = max(data, key=lambda x: x[0])[0] years = [] for y in range(min_year, max_year + 1): years.append(y) # In[14]: print(years) # Now, we want the attempts_per_year to look like (, 0). # In[16]: attempts_per_year = [] for y in years: attempts_per_year.append([y,0]) # In[17]: print(attempts_per_year) # In[26]: for row in data: for ya in attempts_per_year: y = ya[0] if row[0] == y: ya[1] += 1 # In[27]: print(attempts_per_year) # In[28]: get_ipython().run_line_magic('matplotlib', 'inline') barplot(attempts_per_year) # In which year did the most attempts at breaking out of prison with a helicopter occur? # In[29]: countries_frequency = df["Country"].value_counts() # In[30]: print_pretty_table(countries_frequency) # The country with the most helicopter escape attempts is France. # In[ ]: