Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

140
Views
Slicing a CSV dataset by Columns in javascript using d3

I am currently attempting to load a csv file in order to construct a line chart, and I need to know how to load only a subset of the columns.

Say that my data.csv file has 10 columns: Col1,Col2,...,Col10, and I only want to load in the first column, and every even column (Col1,Col2,Col4,...,Col10). I have figured out that in order to do so, a function can be called when the d3.csv() function is called, ie:

const dataset = d3.csv("data.csv", function(){})

And within the function, I need to specify some logic that will return the dataset with the desired columns. I have attempted numerous solutions, but none are outputting the desired dataset with only Col1,Col2,Col4,...,Col10. Specifically I had thought that the solution would be something like:

const dataset = d3.csv("data.csv", function(data){
    let i;
    for (i=1;i%2==0;i++){
        return data[i]
    }
});

I'm really not sure as to how to complete this, as my understanding of JavaScript is still very fresh. Can someone help me to understand how to implement this function correctly? Any insights or guidance are greatly appreciated!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can do it by calling an ananymous funtion with following way

 <html>
<head>
<script src="https://d3js.org/d3.v7.min.js"></script>
<body>
<script>
mydata=
d3.csv("mydata.csv",function(d){
return {col1: d.col1, col2: d.col2}}

).then(function(data) {
  return data;
});

console.log('mydata after removing columns become ...:',mydata);
</script>
</body>
</html>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!