title: Mapping CSV data into new structure
body: <p>I have a csv which contains the following data</p>
  
  <pre><code>this_year   |   minus_one_year  |   minus_two_year  |   minus_three_year
  -------------------------------------------------------------------------
  1           |   2               |   2               |   3
  -------------------------------------------------------------------------
  4           |   5               |   5               |   5
  -------------------------------------------------------------------------
  2           |   2               |   2               |   2
  -------------------------------------------------------------------------
  4           |   5               |   4               |   4
  -------------------------------------------------------------------------
  1           |   2               |   3               |   3
  -------------------------------------------------------------------------
  </code></pre>
  
  <p>I read this csv file and now I need to organise the data.  My end goal is to have the following output</p>
  
  <pre><code>{
    "nodes": [
      {
        "name": "1",
        "node": "this_year"
      },
      {
        "name": "2",
        "node": "this_year"
      },
      {
        "name": "4",
        "node": "this_year"
      },
      {
        "name": "2",
        "node": "minus_one_year"
      },
      {
        "name": "5",
        "node": "minus_one_year"
      },
      {
        "name": "2",
        "node": "minus_two_year"
      },
      {
        "name": "3",
        "node": "minus_two_year"
      },
      {
        "name": "4",
        "node": "minus_two_year"
      },
      {
        "name": "5",
        "node": "minus_two_year"
      },
      {
        "name": "2",
        "node": "minus_three_year"
      },
      {
        "name": "3",
        "node": "minus_three_year"
      },
      {
        "name": "4",
        "node": "minus_three_year"
      },
      {
        "name": "5",
        "node": "minus_three_year"
      }
    ]
  }
  </code></pre>
  
  <p>So for each column, I am getting the unique values.  So this_year has 3 nodes, because the data contains 3 unique values, 1, 2, and 4.</p>
  
  <p>I am using D3 but at the moment this is only involved with the parsing.  For the formatting of data, I think I am on the right track, I am using map.</p>
  
  <p>So far I have something like this</p>
  
  <pre><code>let graph = {"nodes" : [], "links" : []};
  
  graph.nodes = output.map(function(d) { return [
    {
      'name': d.current_month,
      'node': d.value
    }
  ]; });
  
  console.log(graph.nodes)
  </code></pre>
  
  <p>Where output is the csv data.  Obviously this is not working, but getting a bit confused by all this mapping and reducing etc.  So with the data I have, how can I achieve the 
  above output?</p>
  
  <p>I have included a <a href="http://jsfiddle.net/3me0o2zn/4/" rel="nofollow noreferrer">JSFiddle</a> to demonstrate what I have done so far.</p>
  
  <p>Many thanks</p>
  
  <p><strong>UPDATE</strong></p>
  
  <pre><code> d3.csv('churn_status.csv')
      .then(function(data) {
  
          vm.graph.nodes = data.reduce(function(acc, line){
              return acc.concat(Object.entries(line).map(function(column){
                  return {name: column[0], node: column[1]}
              }))}, []);
  
  
          vm.graph.nodes = vm.graph.nodes.sort(function(a,b) { return a.name &gt; b.name ? -1 : 1});
      })
      .catch(function(error){
          // handle error
      });
  </code></pre>