# How to use colType in RDF::FromCSV?

**URL:** <https://root-forum.cern.ch/t/how-to-use-coltype-in-rdf-fromcsv/54155>\
**Category:** Newbie\
**Tags:** rdataframe, root\
**Created:** [March 21, 2023, 8:23am UTC](https://root-forum.cern.ch/t/how-to-use-coltype-in-rdf-fromcsv/54155 "2023-03-21T08:23:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JSHeines](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/ecb155/32.png) [@JSHeines](https://root-forum.cern.ch/u/JSHeines)\
**Post date:** [March 21, 2023, 8:23am UTC](https://root-forum.cern.ch/t/how-to-use-coltype-in-rdf-fromcsv/54155/1 "2023-03-21T08:23:53Z")

</div>

Hi,

I’m trying to read a text file into an RDataFrame, and need to specify that all columns should be of type Double\_t. Here is a toy example to illustrate:

```auto
{
   std::ofstream outfile;
   outfile.open("./toydata.csv");
   outfile << "5,3\n7,8.1\n4.1,4.67\n-1.3,5.01";
   outfile.close();

   auto df1 = ROOT::RDF::FromCSV("./toydata.csv", false);
   auto df2 = ROOT::RDF::FromCSV(
      "./toydata.csv", false, ',', -1, {{"Col0", 'D'}});
   auto df3 = ROOT::RDF::FromCSV(
      "./toydata.csv", false, ',', -1, {{"Col1", 'D'}});
   auto df4 = ROOT::RDF::FromCSV(
      "./toydata.csv", false, ',', -1, {{"Col0", 'D'},{"Col1", 'D'}});

   std::cout << "colTypes = {}" << std::endl;
   df1.Display()->Print();
   std::cout << "colTypes = {{\"Col0\", \'D\'}}" << std::endl;
   df2.Display()->Print();
   std::cout << "colTypes = {{\"Col1\", \'D\'}}" << std::endl;
   df3.Display()->Print();
   std::cout << "colTypes = {{\"Col0\", \'D\'},{\"Col1\", \'D\'}}" << std::endl;
   df4.Display()->Print();
}

```

This prints

```auto
colTypes = {}
+-----+------+------+
| Row | Col0 | Col1 |
+-----+------+------+
| 0 | 5 | 3 |
+-----+------+------+
| 1 | 7 | 8 |
+-----+------+------+
| 2 | 4 | 4 |
+-----+------+------+
| 3 | -1 | 5 |
+-----+------+------+
colTypes = {{"Col0", 'D'}}
+-----+-----------+------+
| Row | Col0 | Col1 |
+-----+-----------+------+
| 0 | 0.0000000 | 0 |
+-----+-----------+------+
| 1 | 0.0000000 | 0 |
+-----+-----------+------+
| 2 | 0.0000000 | 0 |
+-----+-----------+------+
| 3 | 0.0000000 | 0 |
+-----+-----------+------+
colTypes = {{"Col1", 'D'}}
+-----+------+-----------+
| Row | Col0 | Col1 |
+-----+------+-----------+
| 0 | 5 | 0.0000000 |
+-----+------+-----------+
| 1 | 7 | 0.0000000 |
+-----+------+-----------+
| 2 | 4 | 0.0000000 |
+-----+------+-----------+
| 3 | -1 | 0.0000000 |
+-----+------+-----------+
colTypes = {{"Col0", 'D'},{"Col1", 'D'}}
+-----+-----------+-----------+
| Row | Col0 | Col1 |
+-----+-----------+-----------+
| 0 | 0.0000000 | 0.0000000 |
+-----+-----------+-----------+
| 1 | 0.0000000 | 0.0000000 |
+-----+-----------+-----------+
| 2 | 0.0000000 | 0.0000000 |
+-----+-----------+-----------+
| 3 | 0.0000000 | 0.0000000 |
+-----+-----------+-----------+

```

What is happening here? And what is the correct way to specify column type?

_ROOT Version:_ 6.28/00 from conda-forge  
_Platform:_ macosx 10.15.7  
_Compiler:_ Not Provided

* * *

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [March 21, 2023, 3:35pm UTC](https://root-forum.cern.ch/t/how-to-use-coltype-in-rdf-fromcsv/54155/2 "2023-03-21T15:35:18Z")

</div>

Hi @JSHeines ,

thank you for the report! I can reproduce the problem, this is a bug but I don’t know where, exactly, things are going wrong yet.

The only workaround I can suggest at this time is to avoid `colTypes` and add a `.` to the numbers in the first line of the CSV so they are auto-detected as doubles, which works.

Can you please open an issue at [Issues · root-project/root · GitHub](http://github.com/root-project/root/issues) ? I will take a look as soon as possible.

Sorry for the trouble!  
Enrico

---

<div class="post-metadata">

**Author:** ![JSHeines](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/ecb155/32.png) [@JSHeines](https://root-forum.cern.ch/u/JSHeines)\
**Post date:** [March 21, 2023, 4:34pm UTC](https://root-forum.cern.ch/t/how-to-use-coltype-in-rdf-fromcsv/54155/3 "2023-03-21T16:34:19Z")

</div>

Hi @eguiraud,

Thanks for your reply, I have opened [an issue](https://github.com/root-project/root/issues/12520).  
It’s no problem to workaround, reading the file into a TTree also works fine. I was mostly wondering what went wrong.

Thank you for your help  
Johannes

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [March 23, 2023, 2:01pm UTC](https://root-forum.cern.ch/t/how-to-use-coltype-in-rdf-fromcsv/54155/4 "2023-03-23T14:01:53Z")

</div>

HI,

thank you for your report, this is now fixed in the `master` and `v6-28-00-patches` branches (future 6.28.04).

Cheers,  
Enrico
