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

304
Vistas
Reading csv with fast-csv in node.js when 3 columns have same captions

I am trying to read a CSV file with fast-csv in Node.js. The csv file has a header row which contains 90 columns. 87 of them have unique names. But 3 columns have the same header name "Transformation". This is obviously a semantic mistake. Fast-csv is complaining that headers are not unique and does not read the CSV. I know, all column names should be different, but this is how I get the CSV file. Is there a way to read the headers and if some column has a name that another column has, the name automatically converts to "Transformation_int", with int being some random number?

csv.parseFile(csvFileName,
       { headers: true, delimiter: ";", 
         headers: headers => headers.map(
          h => {h.replace( /[\r\n]+/gm, " " )}) 
        })
    .on ("data", function (row) { <doing something> })
    .on ("error", error => {console.log("This error occured:",error)})
    .on ("end", () => {      console.log("Import finished")});
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

you could not use headers at all, and then the first row will contain headers, and you can manually process the rest of the data with reference to the first row as you need, and even keep duplicate names:

headers: false

or, you can pass a transform function which detects duplicates, and also renames them

here's a quick example which renames duplicate headers by adding random number:

csv.parseFile(csvFileName, {
        delimiter: ";",
        headers: headers => {

            // rename duplicate
            headers.map((el, i, ar) => {
                if (ar.indexOf(el) !== i) {
                    headers[i] = `${el}_${i}`;
                }
            });

            return headers;
        }
    })
    .on("data", function(row) {
        console.log('row', row);
    })
    .on("error", error => {
        console.log("This error occured:", error)
    })
    .on("end", () => {
        console.log("Import finished")
    });
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