Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip lines future (Feature Suggestion) #738

Closed
DamirKh opened this issue Nov 14, 2019 · 8 comments
Closed

Skip lines future (Feature Suggestion) #738

DamirKh opened this issue Nov 14, 2019 · 8 comments

Comments

@DamirKh
Copy link

DamirKh commented Nov 14, 2019

It would be great to have the option "skip N lines", since CSV files often contain not commented headers. Can this be implemented?
For example:

This is a data file generated by some old software.
Next line will contain a headers of parameters.
Temperature, Humidity, Voltage
22.5, 45.5, 220
23.0, 44.0, 219
...
In such case "skipLines: 2" could be added to config.

Thanks!

@pokoli
Copy link
Collaborator

pokoli commented Nov 14, 2019

Yes, it makes sense to me. It will be great if you provide a PR adding support for it. Please also include a test case to ensure the behaviour is working correctly.

@DamirKh
Copy link
Author

DamirKh commented Nov 15, 2019

My low English level does not allow me to be sure that I understood you correctly. I'm not a public person and my PR is limited to my friends only. What did You mean "include a test case"? Fork PapaParse and add a automatic test case? I have no any git tools at hand now, but, just to be sure I'm going to right direction, should I add following code to tests/test-cases.js and suggest a patch?

// DamirKh
    {
		description: "Skipped line at beginning",
		input: 'Skipped_line\na,b,c',
		config: { skipLines: 1 },
		expected: {
			data: [['a', 'b', 'c']],
			errors: []
		}
	},
    {
		description: "Two skipped lines at beginning",
		input: 'Skipped_line1\nSkipped_line2\na,b,c',
		config: { skipLines: 2 },
		expected: {
			data: [['a', 'b', 'c']],
			errors: []
		}
	},
    {
                description: "Skipped line at beginning followed by comment line",
		input: 'Skipped_line\n# Comment\na,b,c',
		config: { 
                        skipLines: 1,
                        comments: true
                },
		expected: {
			data: [['a', 'b', 'c']],
			errors: []
		}
	},

@pokoli
Copy link
Collaborator

pokoli commented Nov 15, 2019

Yes, you should include this kind of tests on test tsts-test-cases.js

I will only susgest to add the two of the three sugestesd tests as the first are the second are teting the same but only with a diferent behaviour. It only change the variable used.

@janisdd
Copy link
Contributor

janisdd commented Jun 12, 2021

Why not just parse all and then remove the first N lines of the result??

Here is a one line solution

var result = Papa.parse('the csv data')
var N = 2

[...Array(N)].forEach(_ => result.data.pop())

//result.data has the first N=2 rows removed

@websharik
Copy link

@jscheid, 1) To skip "header" (N lines). 2) To correct parsing with attribute "header". 3) For big files with streaming.

Now i have large file with 4 first rows is "header" (1 row column names, 3 rows props about columns), other data.

@Lonli-Lokli
Copy link

Will it be merged & published?

@pokoli
Copy link
Collaborator

pokoli commented May 17, 2022

@Lonli-Lokli No, I won't merge the PR unless it is green and updated to latest version.
So it needs some work in order to merge it.

bhuvaneshwararaja pushed a commit to bhuvaneshwararaja/PapaParse that referenced this issue Sep 24, 2023
bhuvaneshwararaja pushed a commit to bhuvaneshwararaja/PapaParse that referenced this issue Sep 25, 2023
bhuvaneshwararaja pushed a commit to bhuvaneshwararaja/PapaParse that referenced this issue Sep 26, 2023
bhuvaneshwararaja pushed a commit to bhuvaneshwararaja/PapaParse that referenced this issue Sep 26, 2023
@pokoli
Copy link
Collaborator

pokoli commented Oct 9, 2023

Implemented in #1021 1021

@pokoli pokoli closed this as completed Oct 9, 2023
pokoli pushed a commit that referenced this issue Oct 9, 2023
Co-authored-by: Bhuvaneshwara Raja <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants