我的数据集是我正在加载的.csv文件,然后对一列(第一列)的值求和。我如何修改这个允许我总和超过3列的代码块?
我从一个只有一列的SQL查询中提取.csv。但是我想提取三列并将{3}列的总和存储在def complement[A](predicate: A => Boolean) = (a: A) => !predicate(a)
def any[A](predicates: (A => Boolean)*): A => Boolean =
a => predicates.exists(pred => pred(a))
def none[A](predicates: (A => Boolean)*) = complement(any(predicates: _*))
def every[A](predicates: (A => Boolean)*) = none(predicates.view.map(complement(_)): _*)
。
this.sum
修改 我当前的数据集只是一个列(带有标题)和下面所有行的总和。其他两列中的每一列都是相同的。
// convert our data from the file into an array
var lines = data.replace(/\n+$/, "").split("\n");
// we have array of strings but need an array of Numbers this should do the trick getting rid of any text and 0 values
lines = lines.map(Number).filter(Boolean);
// now we find the sum of all of the values in our array.
this.sum = lines.reduce((a, b) => a + b, 0);