#!/usr/bin/env python # coding: utf-8 # # My First Data Science Project # ## Helicopter Escapes! # We begin by importing some helper functions. # In[29]: from helper import * # ## Get the Data # Now, let's get the data from the [List of helicopter prison escapes](https://en.wikipedia.org/wiki/List_of_helicopter_prison_escapes) Wikipedia article. # In[30]: url = 'https://en.wikipedia.org/wiki/List_of_helicopter_prison_escapes' data = data_from_url(url) # Let's print the first three rows # In[31]: for row in data[:3]: print(row) # ## Removing the Details # In[34]: index = 0 for row in data: data[index] = row[:-1] index += 1 print(data[:3]) # ## Extracting the Year # In[35]: for row in data: date = fetch_year(row[0]) row[0] = date print(data[:3]) # ## Attempts per Year I # In[39]: min_year = min(data, key=lambda x: x[0])[0] max_year = max(data, key=lambda x: x[0])[0] print(min_year) print(max_year) # In[42]: years = [] for y in range(min_year, max_year + 1): years.append(y) print(years) # In[54]: attempts_per_year = [] for y in years: attempts_per_year.append([y, 0]) print(attempts_per_year) # ## Attempts per Year II # In[55]: for row in data: for ya in attempts_per_year: y = ya[0] if row[0] == y: ya[1] += 1 print(attempts_per_year) # ## Attempts per Year III # In[57]: 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? 1986, 2001, 2007, and 2009. # ## Attempts by Country # In[58]: countries_frequency = df["Country"].value_counts() print_pretty_table(countries_frequency) # In which countries do the most attempted helicopter prison escapes occur? France