import ROOT,aa def pythonize_table() : # Table can hold any type... # instantiate a getter for each of the types we care about. types = { 'i' : ROOT.int, 'd' : ROOT.double, 'Ss': ROOT.string } #getattr trick because 'as' is a python keyword :-/ getters = { s : getattr( ROOT.Value, "as" )[t] for s,t in types.items() } def get_value( cell ) : try : return getters[ cell.content.type() ]( cell.content ) except KeyError: print ("cannot get value from table cell of type ", t ) raise TypeError ROOT.Table.get_at = lambda table,col,row: get_value( table.at( col, row )) # assuming the first row holds the column names, return a dict with colname:[value-list] ROOT.Table.as_dict = lambda table : \ { table.get_at(c,0) : [ table.get_at( c,r ) for r in range( 1, table.nrows() ) ] for c in range( 0, table.ncols() ) } def as_dataframe( table ) : import pandas return pandas.DataFrame(data= table.as_dict() ) ROOT.Table.as_dataframe = as_dataframe # add multiple values at once ROOT.Table.oldadd = ROOT.Table.add def table_add ( table, *args ) : for x in args : table.oldadd( x ) return table ROOT.Table.add = table_add pythonize_table()