Skip to content

Instantly share code, notes, and snippets.

@paulgambill
Created October 24, 2013 22:24
Show Gist options
  • Save paulgambill/7146202 to your computer and use it in GitHub Desktop.
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.
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