I am very new to uproot and Python, but hopefully catching up quickly.
I am wondering why the method .pandas()
is creating such a weird table from a TH2D histogram:
myhisto = file["angular_distr_el/ID3_mol_e0_valid/EN_gate/check_cthetaEE_x"]
type(myhisto)
outputs:
uproot.rootio.TH2D
Finally, myhisto.pandas() returns:
count variance
cos(theta) electron energy [eV]
[-inf, -1.0) [-inf, 10.0) 0.0 0.0
[10.0, 10.15) 0.0 0.0
[10.15, 10.3) 0.0 0.0
[10.3, 10.45) 0.0 0.0
[10.45, 10.6) 0.0 0.0
... ... ... ...
[1.0, inf) [24.4, 24.549999999999997) 0.0 0.0
[24.549999999999997, 24.7) 0.0 0.0
[24.7, 24.85) 0.0 0.0
[24.85, 25.0) 0.0 0.0
[25.0, inf) 0.0 0.0
2244 rows × 2 columns
and myhisto.columns
returns:
Index(['count', 'variance'], dtype='object')
Where can I find the documentation of the method .pandas()
to understand what it is doing? Is there a way to reorganise myhisto
in a DataFrame with the right columns?
After some fun but desperate browsing, I understand which type of object it is. It is a very clever way of creating sorted MultiIndex DataFrames. Just typing myhisto.index is possible to see it directly:
The solution is to unstack or create a pivot table of the DataFrame. For this specific object, a pivot table is better, because of the presence of counts AND variance as columns in the original DataFrame. As an example:
vs.
and from here the standard methods of pandas are available!
(To play with slicing techniques like loc[] and iloc[]: https://www.youtube.com/watch?v=tcRGa2soc-c)