mafintosh / mafintosh/csv-parser

[HELP] Why does csv-parser skips headers with empty data?

Open
#181 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
1.5k
Forks
143
PR merge metrics
No merged PRs in 30d

Description

I have a CSV file which I'm reading it row wise. There are some rows which are empty but columns do exists.

The issue is that it doesn't read header name which has no data.

How do I read everything ?

```
function GetRows(headers)
{
StoreHeaders = headers;

StoreHeaders.forEach(header => {

let WordsArray = [];
let CurrentGroupName;

fs.createReadStream('word_groups.csv')
.pipe(csv())
.on('data', (data) => {

if(data[header])
{

WordsArray.push(data[header]);
CurrentGroupName = header;

}

})
.on('end', () => {
console.log(CurrentGroupName);
});
});

}

fs.createReadStream('word_groups.csv')
.pipe(csv())
.on('headers', (headers) => {

GetRows(headers);

});
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the behavior with word_groups.csv using the csv() stream and its headers/data events. Inspect how the parser represents columns with empty values, and compare that with the data[header] condition in the example. Done means establishing whether this is parser behavior or a usage issue and recording the expected handling.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.