Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/ruby -w
- require 'csv'
- old_table = CSV.open('file.csv','r')
- index = [{}, {}, {}, {}, {}] # create one index hash for each column
- multi_key_index = {}
- old_table.each do |row|
- row.each_with_index do |column,col_num|
- (index[col_num][column] ||= []) << row
- end
- (multi_key_index[row[1] + row[2]] ||= []) << row
- end
- ================
- input format for CSV
- * only three options for column 0
- * each column 0 has two other corresponding rows, in this case the last 3 rows make up a set that needs to be extracted and reformatted.
- * every line comes in a set of 3 (although only one set is show here)
- * need to find every corresponding orange and banana row for every apple row that is found
- "apple","John","qwerty",4,7
- "banana","Jane","qwerty",2,7
- "apple","Rachel","zxcv",8,3
- "apple","Bob","asdf",5,4
- "orange","Bob","asdf",4,6
- "banana","Bob","asdf",5,9
- ================
- output format for CSV -- need to
- Columns correspond to "apple","banana","orange",name,asdf (the numbers are from column[3])
- 5,2,4,"Bob","asdf"
Add Comment
Please, Sign In to add comment