Ramis Ramis - 1 year ago 64
Javascript Question

How to export particular columns in CSV format?

I have data.csv file:


To load this file I am using this code:

d3.text("data.csv", function(data) {
parsedCSV = d3.csv.parseRows(data);
// Some data manipulations...
// How to export 2nd & 4th column in CSV format?

How to export 2nd and 4th column from parsedCSV object in CSV fromat?

Answer Source


d3.text("data.csv", function(data) {
    var header = data.split('\n')[0].split(',').map(function(name) {
        return name.trim();
    var parsedCSV = d3.csv.parseRows(data);
    var columns = parsedCSV.map(function(row) {
        return [row[header[1]], row[header[3]]];