0

I'm trying to read in a csv file with D3 and I'm a little stuck. The way my csv file is formatted is that the first line is a merged cell containing a year then the next line will contain the data descriptions (name, age etc).

Currently I have the following:

var resourceList = [{description: "All Yearly Data",
                            name: "yearlyData",
                            path: "data.csv"};

d3.csv(resourceInfo.path, function(error, d) {
    theData.resources[resourceInfo.name].processed = true;
    theData.resources[resourceInfo.name].error = error;
    theData.resources[resourceInfo.name].data = d;
    theData.numProcessed += 1;      
});

This reads the first line in as the data descriptions and then the following lines as actual data. What I want to do is have an multidimensional array which I could go through by year. Is it possible to skip lines while parsing to make sure I can manage that or no?

Thanks!

DragonVet
  • 399
  • 2
  • 6
  • 19

1 Answers1

0

one way of getting at this would be to use filter:

d3.csv(resourceInfo.path, function(error, d) {
    var newData = d.filter(function(obs) { return INSERT YOUR FILTER CONDITION HERE;}); 
    ...

see also:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter?redirectlocale=en-US&redirectslug=JavaScript%2FReference%2FGlobal_Objects%2FArray%2Ffilter

rysloan
  • 707
  • 5
  • 16