Question

Basically I have a csv of the format of shown below:

The csv has 11 columns with the first five and last five being the exact same. I want to be able to read in the csv and store all instances of the first and fifth column (Period and Payout) in a list where they have values and do the same with the sixth and eleventh column in another list.

The purpose of this is to compare payouts that match on period between different lists. Any help whatsoever is appreciated.

Period,IndexId,Id,Date,Payout,,Period,IndexId,Id,Date,Payout    
,,,,,,109,75,80010081,03-Sep-2016 05.28.37,239073.74999996735    
,,,,,,202,75,80044661,21-May-2013 06.49.16,3.0170290500000052E7    
,,,,,,8505,75,80035051,28-May-2013 03.32.41,8835437.250000026    
109,128,80010081,03-Sep-2016 05.28.37,239073.749999967,,,,,,    
202,128,80044661,21-May-2013 06.49.16,3.01702905000001E7,,,,,,    
934,128,80041031,13-Oct-2015 20.22.03,1.55494005E7,,,,,,
Was it helpful?

Solution

Try this one:

var values = File.ReadLines(path).Skip(1)
      .Select(x => x.Split(','))
      .Where(x => x[0] != string.Empty)
      .Select(x => new { Period = x[0], Payout = x[4] })
      .ToList();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top