Skip to content

Instantly share code, notes, and snippets.

@harrisonmalone
Created October 7, 2018 22:27
Show Gist options
  • Save harrisonmalone/4d4d7575c2f35ef083887922acb45e9a to your computer and use it in GitHub Desktop.
Save harrisonmalone/4d4d7575c2f35ef083887922acb45e9a to your computer and use it in GitHub Desktop.
id team city premierships
1 collingwood melbourne 15
2 west coast perth 4
3 brisbane brisbane 3
4 gws sydney 0
5 north melbourne melbourne 4
6 carlton melbourne 16
7 sydney sydney 5
8 melbourne melbourne 12
9 western bulldogs melbourne 2
10 fremantle perth 0
11 gold coast gold coast 0
12 adelaide adelaide 2
13 essendon melbourne 16
14 richmond melbourne 11
15 geelong geelong 9
16 hawthorn melbourne 13
17 st kilda melbourne 1
18 port adelaide adelaide 1
csv = File.read('football_teams.csv')
def parse_csv(csv)
teams = csv.split("\n")
headers = teams[0]
headers = headers.split(",")
headers = headers.map do |header|
header.to_sym
end
teams.delete_at(0)
teams = teams.map do |team|
team.split(",")
end
data = []
teams.each do |team|
hash = {}
team.each_with_index do |value, i|
hash[headers[i]] = value
end
data << hash
end
return data
end
p parse_csv(csv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment