Csvhelper - read / get a single column of all rows?
Hi I'm using csvHelper to read in a csv files with a variable number of
columns. The first row always contains a header row. The number of columns
is unknown at first, sometimes there are three columns and sometimes there
are 30+. The number of rows can be large. I can read in the csv file, but
how do I address each column of data. I need to do some basic stats on the
data (e.g. min, max, stddev), then write them out in a non csv format.
Here is my code so far...
try{
using (var fileReader = File.OpenText(inFile))
using (var csvResult = new CsvHelper.CsvReader(fileReader))
{
// read the header line
csvResult.Read();
// read the whole file
dynamic recs = csvResult.GetRecords<dynamic>().ToList();
/* now how do I get a whole column ???
* recs.getColumn ???
* recs.getColumn['hadername'] ???
*/
}
catch (Exception ex)
{
MessageBox.Show("Error: Could not read file from disk. Original
error: " + ex.Message);
}
Thanks
No comments:
Post a Comment