I am importing a dataset such as this one:
Year,Spain,Rest
2017,"1,688","5,787"
2016,"1,787","5,505"
2015,"1,826","5,187"
2014,"1,822","4,861"
And I need to turn these figures into numbers to display in a D3 graph. I have tried to use this two versions of code to do it but I still get NaN as an answer, so I do not know how to fix this:
d3.csv("stores.csv", function(d, i, columns) {
for (i = 1, t = 0; i < columns.length; ++i) {
t += d[columns[i]] = +d[columns[i]];
}
d.total = t;
return d;
}, function(error, data) {
if (error) throw error;
console.log(data);
var keys = data.columns.slice(1);
data.forEach(function(d) {
d.Year = parseDate(d.Year);
d["Spain"]= +(d["Spain"]);
d["Rest"] = +d["Rest"];
d["total"] = +d["total"];
// ...
Instead of + I tried to use parseInt() in this way:
d["Spain"]= parseInt(d["Spain"]);
but it still does not work.
Hope someone can help me with this.