Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
df032_RDFFromNumpy.py
Go to the documentation of this file.
1## \file
2## \ingroup tutorial_dataframe
3## \notebook
4## Read data from Numpy arrays into RDataFrame.
5##
6## \macro_code
7## \macro_output
8##
9## \date March 2021
10## \author Stefan Wunsch (KIT, CERN)
11
12import ROOT
13import numpy as np
14
15# Let's create some data in numpy arrays
16x = np.array([1, 2, 3], dtype=np.int32)
17y = np.array([4, 5, 6], dtype=np.float64)
18
19# Read the data with RDataFrame
20# The column names in the RDataFrame are defined by the keys of the dictionary.
21# Please note that only fundamental types (int, float, ...) are supported and
22# the arrays must have the same length.
23df = ROOT.RDF.FromNumpy({'x': x, 'y': y})
24
25# You can now use the RDataFrame as usually, e.g. add a column ...
26df = df.Define('z', 'x + y')
27
28# ... or print the content
29df.Display().Print()
30
31# ... or save the data as a ROOT file
32df.Snapshot('tree', 'df032_RDFFromNumpy.root')
void Print(GNN_Data &d, std::string txt="")