Created
February 25, 2018 19:04
-
-
Save b-ryan/6c789e5b9d3686bcfd17904c6e8c158d to your computer and use it in GitHub Desktop.
gun data analysis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import csv | |
with open("gun-data.csv") as f: | |
r = csv.reader(f) | |
head = next(r) | |
i_date = head.index("Date") | |
i_deaths = head.index("Fatalities") | |
i_type = head.index("Type of weapons") | |
results = { | |
"1984-1994": { | |
"n_events": 0, | |
"n_deaths": 0, | |
}, | |
"1994-2004": { | |
"n_events": 0, | |
"n_deaths": 0, | |
}, | |
"2004-2014": { | |
"n_events": 0, | |
"n_deaths": 0, | |
}, | |
} | |
n_events = 0 | |
n_deaths = 0 | |
for line in r: | |
weapons = line[i_type] | |
if "rifle" not in weapons.lower(): | |
continue | |
date = line[i_date] | |
year = int(date.split("/")[2]) | |
if year < 1900: | |
year = 2000 + year | |
if year > 2014 or year < 1984: | |
continue | |
if year > 2004: | |
bucket = "2004-2014" | |
elif year > 1994: | |
bucket = "1994-2004" | |
else: | |
bucket = "1984-1994" | |
results[bucket]["n_events"] += 1 | |
results[bucket]["n_deaths"] += int(line[i_deaths]) | |
print(results["1984-1994"]) | |
print(results["1994-2004"]) | |
print(results["2004-2014"]) |
So I did my own quick analysis and I think that you may have been overly restrictive in your use of rifle
as the predicate, since the Assault Weapons Ban in question also banned pistols and shotguns. My results are much more in keeping with the article. https://github.com/timvisher/gun-violence-analysis
$ lein run
{:bucket "2004-2014", :incidents 23, :deaths 226}
{:bucket "1994-2004", :incidents 8, :deaths 63}
{:bucket "1984-1994", :incidents 9, :deaths 104}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
results: