0

我有一些类似的 CSV UNIX timestamp, price (USD), amount traded (bitcoin)。但是,我还需要交易金额为美元,因此我必须将第 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>

4

0 回答 0