From: snex Date: 2009-06-12T02:45:15+09:00 Subject: Re: Faster CSV,need help with logic On Jun 11, 12:40 pm, Nick Barba wrote: > I'm having a tough time figuring out how to go about solving a specific > problem. > > I have a csv file that looks like this: > > Name,Estimated Hours,Actual Hours,Date > Black, 30, 10, 2009-03-31 > Black,30,10,2009-04-30 > Casey,200,200,2009-04-30 > Clothier,80,40,2009-04-30 > Avino,100,100,2009-05-31 > Black,30,5,2009-05-31 > Clothier,80,50,2009-05-31 > > I need to figure out how to consolidate the rows so that there is just > one row per name, adding any actual hours together, and leaving the > latest date. > > So that would become: > > Name,Estimated Hours,Actual Hours,Date > Casey,200,200,2009-04-30 > Avino,100,100,2009-05-31 > Black,30,25,2009-05-31 > Clothier,80,90,2009-05-31 > > Anyone have any ideas?  I was thinking I would need to start by looking > at the first line, then scan the rest of the file for rows that have > matching names and store all of those. Then write a csv file with just > that new combined line, and then delete all rows with those names.  Then > move onto the next name and do the same thing.  Problem is I can't seem > to figure out how to code it... > -- > Posted viahttp://www.ruby-forum.com/. store everything in a hash table with the name as the key. if the key exists, add the hours and replace the date if necessary, otherwise insert it with the data given.