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

Allow to skip lines from beginning #176

Closed
wants to merge 1 commit into from

Conversation

jschueller
Copy link

This adds possibility to skip lines from the beginning of the file.
Apparently its faster to use std::ignore instead of std::getline but I could not make it work.

What do you think @d99kris ?

@d99kris d99kris self-assigned this Jan 8, 2025
@d99kris
Copy link
Owner

d99kris commented Jan 19, 2025

Hi @jschueller thanks for suggesting a new functionality (and providing a PR). Have you seen the LabelParams argument? It might already provide the functionality you are looking for.

You can use LabelParams(n, -1) which will skip lines until line n (zero-based) and then read the column labels from that line (if there are no labels you'd specify n - 1). For a CSV file with say 3 leading lines to ignore like this:




Open,High,Low,Close,Volume,Adj Close
64.529999,64.800003,64.139999,64.620003,21705200,64.620003
64.419998,64.730003,64.190002,64.620003,20235200,64.620003
64.330002,64.389999,64.050003,64.360001,19259700,64.360001
64.610001,64.949997,64.449997,64.489998,19384900,64.489998
64.470001,64.690002,64.300003,64.620003,21234600,64.620003

You can use n = 3

  rapidcsv::Document doc("examples/colhdr.csv", rapidcsv::LabelParams(3, -1));
  std::vector<float> col = doc.GetColumn<float>("Close");
  std::cout << "Read " << col.size() << " values." << std::endl;

If the data has no column labels you'd use n = 2.

Let me know if this would work or if I am missing some aspect that the PR handles?

There may be some room for improvement in the documentation for this though, I will try to look into that separately.

@jschueller
Copy link
Author

indeed this seems to work

@jschueller jschueller closed this Jan 20, 2025
@jschueller jschueller deleted the skip branch January 20, 2025 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants