#!/usr/bin/env python # coding: utf-8 # # Analyzing Data # ## Prison Helicopter Escapes # We begin by importing some helper functions # In[21]: 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[22]: url = 'https://en.wikipedia.org/wiki/List_of_helicopter_prison_escapes' data = data_from_url(url) # Let's print the first three rows # In[23]: for d in data[:3]: print(d) # ### Fetching only year and saving back to the data # In[33]: index = 0 for row in data: row[0] = fetch_year(row[0]) data[index] = row[:-1] print(row) index+=1 # ### # In[34]: 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[44]: years = [] attempts_per_year = [] each_year = [] for year in range(min_year, max_year+1): years.append(year) for year in years: times = data.count(year) each_year.append(year) each_year.append(times) attempts_per_year.append(each_year) each_year = [] for row in data: for year_attempt in attempts_per_year: if row[0]==year_attempt[0]: year_attempt[1]+=1 print (attempts_per_year) # ### In which year did the most attempts at breaking out of prison with a helicopter occur? # In[45]: get_ipython().run_line_magic('matplotlib', 'inline') barplot(attempts_per_year) # ### In which country did the most attempts at breaking out of prison with a helicopter occur? # In[49]: countries_frequency = df["Country"].value_counts() print_pretty_table(countries_frequency) # In[ ]: