我正在使用 scikit learn 建立一个机器学习项目。输入数据是平面 ROOT NTuples。
过去我一直使用 root_numpy 将 NTuples 转换为保存在 h5 文件中的 pandas.DataFrame 。
我想知道我是否可以使用 uproot 来
a) 完全跳过 h5 转换?
b) 不使用与从 h5 加载到 DataFrame 中一样多的内存?
我天真的第一次尝试看起来像这样:
'''
Runs preselection, keeps only desired variables in DataFrame
'''
def dropAndKeep(df, dropVariables=None, keepVariables=None, presel=None, inplace=True):
if ((presel is not None) and (not callable(presel))):
print("Please either provide a function to 'presel' or leave blank")
raise ValueError
if callable(presel):
if not(inplace):
df = df.drop(df[~presel(df)].index, inplace=False)
else:
df.drop(df[~presel(df)].index, inplace=True)
if keepVariables is not …Run Code Online (Sandbox Code Playgroud)