Comments (5)
If you want to use header: true
, you must remove the first couple of lines before running it through papaparse - here are some suggestions.
Otherwise, you'll have to use header: false
and map the columns yourself. You can do it like this:
this.papa.parse(csv, {
skipEmptyLines: true,
header: true,
complete: (results )=> {
for (let i = 2; i < results.data.length; i++) { // Notice that i changed i to 2, so that we skip the line 0 and 1.
let tradehistory = {
Date: results.data[i][0],
Side: results.data[i][1],
(...)
};
this.loading = false;
this.test.push(tradehistory);
}
console.log("Parsed: k", results.data);
}
});
from ngx-papaparse.
Hi.
I'm sorry - unfortunately the underlying library does not seem to support this. However, you could simply skip / unset the first couple of rows (depending on how you work with the parsed data).
I actually had a similar issue with some bank statements, since the banks sometimes add a few lines with metadata, before the transactions. I solved it by skipping the first X number of items in the outputted array, when working with the data.
from ngx-papaparse.
Hi @alberthaff.
Thanks for your response. One last thing. Can you spare a minute to point me out where should I skip or slice the first two rows. This is my code for parsing csv.
this.papa.parse(csv, {
skipEmptyLines: true,
header: true,
complete: (results )=> {
results.data.splice(0, 1);
for (let i = 0; i < results.data.length; i++) {
let tradehistory = {
Date: results.data[i].Date,
Side: results.data[i].Side,
ConfNumber: results.data[i].ConfNumber,
Stock: results.data[i].Stock,
Shares: results.data[i].Shares,
PhpShare: results.data[i].PhpShare,
Fees: results.data[i].Fees,
Total: results.data[i].Total,
};
this.loading = false;
this.test.push(tradehistory);
}
console.log("Parsed: k", results.data);
}
});
As you can see, I am splicing the index 1 in results array which I think will proceed to the 3rd row. Then I am creating a new array which will contain my desired result. However, this does not solve my issue and I am also aware that setting the header to true will create an objects of row, setting to false will create an array for each row. I am actually confused where did you put the code that skips the row.
This is the result of my code.
The object keys are still the first row.
Any help would be appreaciated, Thank you so much for helping.
from ngx-papaparse.
Thanks for the patience. Exactly what I was thinking, I cannot do it when header is true. Thanks again. 👍
from ngx-papaparse.
You're welcome
from ngx-papaparse.
Related Issues (20)
- Error: Can't resolve 'papaparse/papaparse.min.js' wiht ngx-papaparse@6 HOT 7
- Angular 15 Ivy Engine HOT 4
- RenamedHeaders not present in metadata
- Update dev-environment to NG 8
- Thank you @alberthaff for maintaining this project HOT 1
- PapaParseModule missing, update documentation HOT 4
- Type definitions are incorrect HOT 5
- Result as Observable
- Please update for Angular 9 HOT 2
- Please publish v5 to npm HOT 1
- Angular10 reports a CommonJS warning for PapaParse HOT 2
- ERROR in node_modules/ngx-papaparse/lib/papa.d.ts:5:22 HOT 7
- Angular 10 - unable to install HOT 1
- CommonJS or AMD dependencies can cause optimization bailouts HOT 2
- Entry point 'ngx-papaparse' contains deep imports using Angular 9 HOT 6
- Assign CSV results while complete callback triggered, but results are blank
- Preserve a leading zero HOT 1
- An accessor cannot be declared in an ambient context. HOT 1
- Enabled serviceworkers, but page still freezes while CSV file is being parsed HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ngx-papaparse.