使用jquery-csv将CSV中的列相乘

时间:2017-09-26 09:32:50

标签: javascript jquery csv jquery-csv

我有一些类似UNIX timestamp, price (USD), amount traded (bitcoin)的CSV。但是,我还需要交易金额为美元,因此我必须将第3列与第2列相乘。有人知道怎么做吗?

目前我正在使用jquery-csv

var originalCsv = `1366383202,748.680000000000,1.000000000000
1366471506,777.440000000000,2.700000000000
1368121200,685.740000000000,2.187400000000
1375783458,619.500000000000,1.000000000000`

// Parse multi-line CSV string into a 2D array
// https://github.com/evanplaice/jquery-csv

var newCsvTemp = $.csv.toArrays(originalCsv);

// jquery-csv's arrays are made up of strings, but we need them to be numbers

// Trim whitespace and then convert to Number

var newCsv = newCsvTemp.map(row => row.map(el => Number(el.trim())));

// Multiply amount traded with price

// var newCsvMultiplied = newCsv.map();

$(".new").text($.csv.fromObjects(newCsv));
$(".original").text(originalCsv);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://rawgit.com/evanplaice/jquery-csv/master/src/jquery.csv.min.js"></script>
<h1>New CSV</h1>
<pre class="new"></pre>
<h1>Original CSV</h1>
<pre class="original"></pre>

0 个答案:

没有答案