0

I am trying to create a new csv, with selective columns, from Original csv I have.

I have successfully created csv but the issue is new csv has around 3.5K less rows than the original.

I can't understand why this is happening.

I have tried same code for another csv and it worked fine.

I think their might be some issue in csv(It was originally xlsx, I converted into csv), But I don't know what.

Below is the code I use to create CSV

var ar = [];
  fs.createReadStream(`${inpath}.csv`)
  .on("error", (err) => {
    console.log("error agya");
    throw err;
  })
    .pipe(csv())
    .on("data", (row) => {
      ++j;
      ar.push({
        key: row.Key,
        geoHash: latLonGeoHash.encode(row.Latitude,row.Longitude,6),
        latitude: row.Latitude,
        longitude: row.Longitude
      });
    })
    .on("end", () => {
      stringify(
        ar,
        {
          header: true,
        },
        function (err, output) {
          fs.writeFile(
            `${outpath}.csv`,
            output,
            (err) => err && console.log(err)
          );
        }
      );
      console.log("khtm");
    });

0 Answers0