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

Getter most precise #39

Closed
ghost opened this issue Dec 1, 2019 · 3 comments
Closed

Getter most precise #39

ghost opened this issue Dec 1, 2019 · 3 comments

Comments

@ghost
Copy link

ghost commented Dec 1, 2019

I wish know names of cols and rows rapid...

now I have implemented in my Konectik tool (ANN algorithm), this exemple of a part in my code:

CSVLoader::CSVLoader(string filepath, string separator){
    std::ifstream in(filepath);
    if (in.is_open()){
        string line;
        getline(in, line);
        in.close();
        vector<string> headercolnames;
        size_t position = line.find(separator);
        while (position != string::npos){
            headercolnames.push_back(line.substr(0,position));//here I collect names of cols header...
            line = line.substr(position+1, line.size());
            position = line.find(separator);
        }
        rapidcsv::Document doc(filepath, rapidcsv::LabelParams(0, -1));
        int long npos = 0;
        for (auto it=headercolnames.begin(); it!=headercolnames.end(); ++it){
            vector<float> col = doc.GetColumn<float>((*it));
            //XDATA[lpos][npos] = val;
            int long lpos = 0;
            for (auto itc=col.begin(); itc!=col.end();  ++itc){
                if ((*it).find("y")==0){
                    YDATA[lpos][npos] = (*itc);
                }
                else {
                    XDATA[lpos][npos] = (*itc);
                }
                lpos++;
            }
            npos++;
        }
    }
    else{
        cerr << filepath << " CANNOT BE OPEN !" << endl;
        exit(1);
    }
}

If I don't understand and no see, tell me.

@d99kris
Copy link
Owner

d99kris commented Dec 1, 2019

I believe you should be able to get the column names using something like this (instead of manually reading it):

std::vector<std::string> headercolnames = doc.GetColumnNames();

If there still are problems, please help share the CSV file you are attempting to read. Or just the first 3 lines. Then I can help run a quick test on my side and help debug. Thanks!

@d99kris
Copy link
Owner

d99kris commented Dec 8, 2019

Let me know if you are still facing issues, otherwise I will close this issue tomorrow. Thanks.

@d99kris
Copy link
Owner

d99kris commented Jan 14, 2020

Closing this issue, please re-open if you are still facing issues.

@d99kris d99kris closed this as completed Jan 14, 2020
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

No branches or pull requests

1 participant