score:0

You can use d3.text to load the CSV data, and then iterate over the text to create an array of objects with named values, which could then be stacked or whatever you would normally do in D3 with your data

d3.text("data.csv", function(text) {

    console.log(text);

    var data = []

    d3.csvParseRows(text).forEach(function(row) {
      let obj = {}
        row.forEach(function(value, i) {    
        let pairIndex = Math.floor((i - 1) / 2)
        //assume first value is the index or name for the row, eg A, B, etc
        if (i == 0) { 
          obj.index = value 
        } 
        else if (i % 2 == 0) {           
          let v = "age2-" + pairIndex
          obj[v] = value
        } else {
          let v = "age1-" + pairIndex
          obj[v] = value
        }
      });
      data.push(obj)
    });

    console.log(data);
// continue with your code

Related Query

More Query from same tag