How to access the index of rapidcsv::Document #183
Closed
empeirikos
started this conversation in
Q&A
Replies: 2 comments
-
|
Hi @empeirikos - yes rapidcsv provides With this example program: rapidcsv::Document doc("examples/colrowhdr.csv", rapidcsv::LabelParams(0, 0));
std::vector<std::string> rowNames = doc.GetRowNames();
for (const auto& rowName : rowNames)
{
std::cout << rowName << "\n";
}The output would be: For input file Hope this helps! |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Yes it definitely does. Thanks for writing this library!
…On Sun, 9 Feb 2025 at 04:10, Kristofer Berggren ***@***.***> wrote:
Hi @empeirikos <https://github.com/empeirikos> - yes rapidcsv provides
GetRowNames() for getting a vector of row labels (and similarly a
GetColumnNames()).
With this example program:
rapidcsv::Document doc("examples/colrowhdr.csv", rapidcsv::LabelParams(0, 0));
std::vector<std::string> rowNames = doc.GetRowNames();
for (const auto& rowName : rowNames)
{
std::cout << rowName << "\n";
}
The output would be:
2017-02-24
2017-02-23
2017-02-22
2017-02-21
2017-02-17
For input file colrowhdr.csv content:
Date,Open,High,Low,Close,Volume,Adj Close
2017-02-24,64.529999,64.800003,64.139999,64.620003,21705200,64.620003
2017-02-23,64.419998,64.730003,64.190002,64.620003,20235200,64.620003
2017-02-22,64.330002,64.389999,64.050003,64.360001,19259700,64.360001
2017-02-21,64.610001,64.949997,64.449997,64.489998,19384900,64.489998
2017-02-17,64.470001,64.690002,64.300003,64.620003,21234600,64.620003
Hope this helps!
—
Reply to this email directly, view it on GitHub
<#183 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ATE2KDRU3QKVM6V55BG5IIL2O3ILNAVCNFSM6AAAAABWXWBFT6VHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTEMJQGY2TQOI>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
When reading a csv file,
rapidcsvuses the first column to create a handy alternative index for accessing different rows. In Python'sDataFrameone can access this index usingpandas.DataFrame.index. Is there a similar method inrapidcsv; ideally I would like to keep dates as an index but also copy it to a vector of dates that I can use for other purposes.Beta Was this translation helpful? Give feedback.
All reactions