Skip to content Skip to sidebar Skip to footer

Importing Csv Without Headers Into D3 - Data With Both Numbers And Strings

I'm working on a visualization where I need to import some csv data. Let's say the csv file looks something like this: 1,4,abc 2,7,def 3,5,ghi ... The csv file does not have a hea

Solution 1:

You can use the index of the element in the map function to see whether it should be converted to a number:

input = d3.csv.parseRows(text).map(function(row) {
    return row.map(function(value, index) {
        if(index == 2) {
            return value;
        } else {
            return +value;
        }
    });
});

This will only work for your specific case though.

Post a Comment for "Importing Csv Without Headers Into D3 - Data With Both Numbers And Strings"