Answer the question
In order to leave comments, you need to log in
Grouping and Summing values from CSV file using Linq C#?
I am a beginner and trying to figure out the task, there is a CSV file that contains data in one column , example:
03 /03/
2020,100 03/04/2020,150 04/09/
2020,130 04/10/
2020,150 Note:
DateTime, Value
You need to group the data for 1 month (sum up their values) and get the average value for the month (for example, there are 4-5 sales in a month, here you need the sum per month / for the number of values in the same month)
var result = lstTest
.Select(row => row.Split(','))
.GroupBy(row => DateTime.Parse(row[0]), row => int.Parse(row[1]), (date, val) => new { Date = date, Value = val }) //.Average()
.GroupBy(x => x.Date.Month, x => x.Value.Average());
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question