I have a big array with data. I want to sum columns with one or two conditions. The data is already stored as classes in a dictionary.
The data is quite extensive, but the important part looks like this;
[["Gothenburg", "2018-01-05", "jan", 1.5, 2.3, 107],
["Gothenburg", "2018-01-15", "jan", 1.3, 3.3, 96],
["Gothenburg", "2018-01-25", "jan", 1.7, 3.2, 45],
["Gothenburg", "2018-03-05", "mar", 1.5, 2.1, 96],
["Gothenburg", "2018-03-05", "mar", 1.9, 2.8, 102],
["Malmo", "2018-01-02", "jan", 1.6, 2.3, 104],
["Malmo", "2018-01-10", "jan", 1.0, 2.9, 112],
["Malmo", "2018-03-05", "mar", 0.7, 4.3, 151],
["Malmo", "2018-03-25", "mar", 1.0, 3.3, 98],
["Hallsberg", "2018-01-25", "jan", 2.5, 2.3, 87],
["Hallsberg", "2018-02-14", "feb", 2.2, 2.3, 168],
["Hallsberg", "2018-03-06", "mar", 3.7, 2.3, 142],
["Hallsberg", "2018-04-29", "apr", 2.7, 2.3, 100]]
Explanation of columns: 0 = city, 1 = date, 2 = month, 3 = meanvalue1, 4 = meanvalue2, 5 = meanvalue3
The array is about 8000 rows in total with maybe 300 different cities.
What i want to achieve is to sum columns 3, 4, 5 after value in column 0, 1, 2.
For example sum of column 3 with key "Malmo" = 1.6 + 1.0 + 0.7 + 1.0 = 4.3 sum of column 3 with key "Malmo" and "jan" = 1.6 + 1.0 = 2.6
These conditional sums could either be stored in a dictionary (or a better solution), or they can be displayed att screen.
I guess there is a clever way to do this quite easy, but i haven't figured it out. I have tried to use for-loops and if cases, but it's messy. Hope to get some good advices here!