I have a .csv file that looks like:
The Start Date, The User Id, The User Name,
date, id, name,
12-12-12, 12345, John Doe
01-02-13, 67891, Jane Doe
The d3.csv()
function does both the loading and the parsing without giving you a chance to intervene. Since you need to intervene, you'll want to load the csv as plain text –– without parsing it –– then remove the first line, and then pass it as a String into the csv module for parsing.
For loading, use d3.xhr() For parsing, use d3.csv.parse().
You should end up with something like this:
d3.xhr('data.csv').get(function (err, response) {
var dirtyCSV = response.responseText;
var cleanCSV = dirtyCSV.split('\n').slice(1).join('\n');
var parsedCSV = d3.csv.parse(cleanCSV);
})
Here is a less costly transformation than the one above (this has not been tested/debugged):
d3.xhr('data.csv').get(function (err, response) {
var dirtyCSV = response.responseText;
var firstEOL = dirtyCSV.indexOf('\n');
var parsedCSV = d3.csv.parse(cleanCSV.substring(firstEOL+1));
})
For those who want to ignore certain rows from csv, following snippet can be used.
//Read the data
d3.csv("abc.csv?"+Math.random(),
function(d){
//if current row's value column is blank, then ignore it. Otherwise do further process.
if(d.value!=''){
return { date : d3.timeParse("%Y-%m-%d %H:%M:%S")(d.date), value : d.value }
}
},