# I have a large root file, but when using pyroot, the for loop is too slow, is there any good way to deal with it?

**URL:** <https://root-forum.cern.ch/t/i-have-a-large-root-file-but-when-using-pyroot-the-for-loop-is-too-slow-is-there-any-good-way-to-deal-with-it/57928>\
**Category:** ROOT\
**Tags:** python, root\
**Created:** [January 23, 2024, 6:26am UTC](https://root-forum.cern.ch/t/i-have-a-large-root-file-but-when-using-pyroot-the-for-loop-is-too-slow-is-there-any-good-way-to-deal-with-it/57928 "2024-01-23T06:26:52Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [January 23, 2024, 7:44am UTC](https://root-forum.cern.ch/t/i-have-a-large-root-file-but-when-using-pyroot-the-for-loop-is-too-slow-is-there-any-good-way-to-deal-with-it/57928/2 "2024-01-23T07:44:18Z")

</div>

> [@RDataFrame in python loop](https://root-forum.cern.ch/t/rdataframe-in-python-loop/46905):
>
> Dear, I heard that RDataFrame is much efficient than classic loops, but I’m not sure how to use it for a simple code as in python: chain = ROOT.TChain() chain.Add(Dataset) h = ROOT.TH1D(“h”,"", n, x\_min, x\_max) lvmu1=ROOT.TLorentzVector() lvmu2 =ROOT.TLorentzVector() for ev in chain: lvmu1.SetPtEtaPhiE(ev.pt\_muon[0], ev.eta\_muon[0], ev.phi\_muon[0], ev.E\_muon[0]) lvmu2.SetPtEtaPhiE(ev.pt\_muon[1], ev.eta\_muon[1], ev.phi\_muon[1], ev.E\_muon[1]) lvmu3 = lvmu1+ lvmu2 h.Fill(lvmu3.Pt())

---

_[View the full topic](https://root-forum.cern.ch/t/i-have-a-large-root-file-but-when-using-pyroot-the-for-loop-is-too-slow-is-there-any-good-way-to-deal-with-it/57928)._
