Created
October 24, 2013 22:24
-
-
Save paulgambill/7146202 to your computer and use it in GitHub Desktop.
This Ruby script parses the dataset from https://catalog.data.gov/dataset/baby-names-from-social-security-card-applications-data-by-state-and-district-of- to find the top name for each sex/year/state permutation. The result is a .csv with a row for each year/sex/top name combination. Be sure to replace the path on line 7 with your local path.
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
require 'csv' | |
year = 1910 | |
CSV.open("stateNamesParsed.csv", "ab") do |csv| | |
Dir.glob('PATH/*.TXT') do |file| | |
next if file == '.' or file == '..' | |
File.open(file).readlines.each do |line| | |
array = line.split(',') | |
if array[2] == year.to_s | |
csv << [array[0], array[1], array[2], array[3], array[4]] | |
if year == 2012 | |
year = 1910 | |
else | |
year += 1 | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment