How do I draw a histogram with a condition?

Hi. I have a simple question in root python.

Let’s say I’m trying to plot a histogram of column X such that column Y==1. Is there a way of doing it inside the definition of the histogram and not to define new columns, etc?

I mean something like this:

h = df.Histo1D(“X”, “Y==1”)
c = ROOT.TCanvas()
h.Draw()
c.Draw()

Assume that each event (row) in the dataframe can have multiple entries, such that they can have different Y’s.

Sometimes I want to do a quick check and defining new columns takes too long.

Thank you

ROOT Version: JupyROOT 6.30/04
Platform: Jupyter


Hello,

You cannot filter events directly in the Histogramming Action.
In RDataFrame, the filtering should happen with Filter:

h = df.Filter('Y==1').Histo1D('X')

Cheers,
D

1 Like