Reputation:
I have a CSV file which simply contains only numbers per line
example
12,34,56
1,2,3
34,45,67
I would like to get the maximum ,minimum and average of each row.
I started coding
from str in File.ReadLines(@"FilePath")
.Select(x => Convert.ToInt32(x))
But I am not sure how to separte the values from CSV file and project the maximum,minimum,average of each row.
If you still need more information , i am happy to provide.
Upvotes: 0
Views: 68
Reputation:
You could use the following code snippet
var result = from str in File.ReadLines(@"FilePath")
let GetValue = str.Split(',')
.Select(x => Convert.ToInt32(x))
select new
{
Maximum = GetValue.Max(),
Minimum = GetValue.Min(),
Average = GetValue.Average()
};
I have simulated the result
IEnumerable<string> lines = new[] { "1,2,3", "4,5,6", "45,56,67" };
var result = from str in lines
let GetValue = str.Split(',')
.Select(x => Convert.ToInt32(x))
select new
{
Maximum = GetValue.Max(),
Minimum = GetValue.Min(),
Average = GetValue.Average()
};
Upvotes: 1