1

I have an issue I can't wrap my head around. I have a CSV file with the following columns:
Name Info1 Info2 Value1 Value2 Value3 Value3

From this, using d3.csv, I am trying to create a javascript array that looks like this, for each row in of the data:

[{key: Name,
    Info1: Info1,
    Info2: Info2,
    values: [{
        Value1: Value1,
        Value2: Value2,
        Value3: Value3
    }]
}]

Can't really wrap my head around how to do this. Anyone?

Edit: Problem solved. Now, how can I operate on the sub-array of values, for example for each key separately extract the mean?

Edit 2: Never mind, solved that.

1 Answer 1

3

This will do it (change the filename to what you need)

d3.csv("dataset.csv", function(data) {
  dataset = data.map(function(d) {
    return {
      key: d.Name,
      Info1: d.Info1,
      Info2: d.Info2,
      values: [{
        Value1: d.Value1,
        Value2: d.Value2,
        Value3: d.Value3
      }]
    };
  });

  return dataset;
});

Demo at http://plnkr.co/edit/aVfrCC?p=preview

Sign up to request clarification or add additional context in comments.

1 Comment

So straightforward I should really have been able to figure it out myself. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.