Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

141
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda