Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

135
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda