To read the .csv file having date in the form dd/mm/yy

I am having .csv file which contains two columns one of which is the date as dd/mm/yy form and other the y axis value.
I need to draw the graph between both of these columns with date in x axis and the other one in y axis.
I have done it earlier for .dat and .txt file but with .csv its not working. code is like :-

{TNtuple calls("calls","calls","time:cloud water path ice mean");

TCanvas *a1 = new TCanvas("a1","canvas");
calls.Draw("cloud water path ice mean:time");

htemp->SetTitle("water path ice mean ; time ; % deviation");


Now,can anyone help me out in this please?
the file contains some description in the first few rows and columns and then after that it starts with the data column wise.

You could use code like the following to convert the string from dd/mm/yy to epoch (a time_t).

time_t dmyToEpoch(const char *dmy) {
    tm the_time = {0};
    auto last_valid_char = strptime(dmy, "%d/%m/%y", &the_time);
    if (last_valid_char && *last_valid_char == '\0')
        return mktime(&the_time);
    std::cerr << "Invalid datetime: " << dmy << "\n";
    return 0;

I don’t think you can do it directly via ReadFile. It might be easier to preprocess the file using a scripting language.

preprocess means to make that change in some other format or what? so ROOT doesn’t read the data file in the csv form?

I’d simply try

perl -MDateTime -wpE'sub e{DateTime->new(day=>$_[0],month=>$_[1],year=>2000+$_[2])->epoch}s#\b(\d\d)/(\d\d)/(\d\d)\b#e($1,$2,$2)#eg' infile.csv > outfile.csv

It replaces everything that looks like a date in format dd/mm/yy with the epoch (assumes you are in date 2000+yy). Later in ROOT, you can format the axis using SetTimeDisplay / SetTimeFormat.

There are probably a lot of other solutions as well.

Ok,so that seems to take care for the time part but,i am not able to read the csv file only now as before the plotting i need to make that read.
I am still looking for the solution on how to make that read it.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.