# How to import data from ROOT in Jupyter Notebook?

**URL:** <https://root-forum.cern.ch/t/how-to-import-data-from-root-in-jupyter-notebook/44383>\
**Category:** Newbie\
**Tags:** python, root\
**Created:** [April 12, 2021, 2:36pm UTC](https://root-forum.cern.ch/t/how-to-import-data-from-root-in-jupyter-notebook/44383 "2021-04-12T14:36:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shivam\_Raj](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/shivam_raj/32/22160_2.png) [@Shivam\_Raj](https://root-forum.cern.ch/u/Shivam_Raj)\
**Post date:** [April 12, 2021, 2:36pm UTC](https://root-forum.cern.ch/t/how-to-import-data-from-root-in-jupyter-notebook/44383/1 "2021-04-12T14:36:21Z")

</div>

I want to import data as a .root file in Jupyter Notebook but did not understand how to open the trees inside the file after importing?

if I am doing this:  
import ROOT

f = ROOT.TFile.Open(“signal.root”)  
for event in f.tagsDumper :  
print (event.tress)

## obtaining this as output

TypeError Traceback (most recent call last)  
 in   
2  
3 f = ROOT.TFile.Open(“signal.root”)  
----\> 4 for event in f.tagsDumper :  
5 print (event.tress)

TypeError: ‘TDirectoryFile’ object is not iterable

_ROOT Version:_ 6.22.06  
_Platform:_ Linux  
_Compiler:_ Jupyter notebook

* * *

---

<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:** [April 13, 2021, 8:48am UTC](https://root-forum.cern.ch/t/how-to-import-data-from-root-in-jupyter-notebook/44383/2 "2021-04-13T08:48:09Z")

</div>

Hi @Shivam_Raj ,  
you need to extract the dataset (i.e. the TTree object) from the file you opened and then iterate on _that_.  
However note that explicit Python for loops are the slowest way to run over ROOT data in Python. @etejedor might be able to point you to some learning resources.

Cheers,  
Enrico

---

<div class="post-metadata">

**Author:** ![etejedor](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/e79b87/32.png) [@etejedor](https://root-forum.cern.ch/u/etejedor)\
**Post date:** [April 13, 2021, 8:54am UTC](https://root-forum.cern.ch/t/how-to-import-data-from-root-in-jupyter-notebook/44383/3 "2021-04-13T08:54:08Z")

</div>

Hi,

As @eguiraud pointed out, you are probably trying to iterate on a directory (i.e. `tagsDumper` is not a tree, but a directory).

Here’s some docs on TTree from Python (look for PyROOT box):

[https://root.cern.ch/doc/master/classTTree.html](https://root.cern.ch/doc/master/classTTree.html)

also this example might help

[https://swan-gallery.web.cern.ch/notebooks/root\_primer/OldSummerStudentsCourse/2017/examples/notebooks/TTreeAccess\_Example\_py.html](https://swan-gallery.web.cern.ch/notebooks/root_primer/OldSummerStudentsCourse/2017/examples/notebooks/TTreeAccess_Example_py.html)

---

<div class="post-metadata">

**Author:** ![Shivam\_Raj](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/shivam_raj/32/22160_2.png) [@Shivam\_Raj](https://root-forum.cern.ch/u/Shivam_Raj)\
**Post date:** [April 14, 2021, 4:47am UTC](https://root-forum.cern.ch/t/how-to-import-data-from-root-in-jupyter-notebook/44383/4 "2021-04-14T04:47:32Z")

</div>

Thank you for clarification @eguiraud

---

<div class="post-metadata">

**Author:** ![Shivam\_Raj](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/shivam_raj/32/22160_2.png) [@Shivam\_Raj](https://root-forum.cern.ch/u/Shivam_Raj)\
**Post date:** [April 14, 2021, 4:53am UTC](https://root-forum.cern.ch/t/how-to-import-data-from-root-in-jupyter-notebook/44383/5 "2021-04-14T04:53:45Z")

</div>

Thank you @etejedor for sending helpful links.
