ROOT
v6-34
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
12
import
ROOT
13
import
numpy
as
np
14
15
# Let's create some data in numpy arrays
16
x =
np.array
([1, 2, 3], dtype=
np.int32
)
17
y =
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.
23
df =
ROOT.RDF.FromNumpy
({
'x'
: x,
'y'
: y})
24
25
# You can now use the RDataFrame as usually, e.g. add a column ...
26
df =
df.Define
(
'z'
,
'x + y'
)
27
28
# ... or print the content
29
df.Display
().
Print
()
30
31
# ... or save the data as a ROOT file
32
df.Snapshot
(
'tree'
,
'df032_RDFFromNumpy.root'
)
TRangeDynCast
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Definition
TCollection.h:358
Print
void Print(GNN_Data &d, std::string txt="")
Definition
TMVA_SOFIE_GNN_Application.C:59
tutorials
dataframe
df032_RDFFromNumpy.py
ROOT v6-34 - Reference Guide Generated on Fri Jan 24 2025 14:44:17 (GVA Time) using Doxygen 1.10.0