ROOT
v6-26
Reference Guide
Loading...
Searching...
No Matches
df032_MakeNumpyDataFrame.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.MakeNumpyDataFrame({
'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_MakeNumpyDataFrame.root'
)
tutorials
dataframe
df032_MakeNumpyDataFrame.py
ROOT v6-26 - Reference Guide Generated on Mon Sep 11 2023 21:03:01 (GVA Time) using Doxygen 1.9.8