ROOT
v6-32
Reference Guide
Loading...
Searching...
No Matches
df035_RDFFromPandas.py
Go to the documentation of this file.
1
## \file
2
## \ingroup tutorial_dataframe
3
## \notebook
4
## Read data from Pandas Data Frame into RDataFrame.
5
##
6
## \macro_code
7
## \macro_output
8
##
9
## \date February 2024
10
## \author Pere Mato (CERN)
11
12
import
ROOT
13
import
pandas
as
pd
14
15
# Let's create some data in a pandas dataframe
16
pdf = pd.DataFrame({
'x'
: [1, 2, 3],
'y'
: [4, 5, 6]})
17
18
# Convert the Pandas DataFrame to RDataFrame
19
# The column names are directly copied to the RDF
20
# Please note that only fundamental types (int, float, ...) are supported and
21
# the arrays must have the same length.
22
df = ROOT.RDF.FromPandas(pdf)
23
24
# You can now use the RDataFrame as usually, e.g. add a column ...
25
df = df.Define(
'z'
,
'x + y'
)
26
27
# ... or print the content
28
df.Display().
Print
()
29
30
# ... or save the data as a ROOT file
31
df.Snapshot(
'tree'
,
'df035_RDFFromPandas.root'
)
Print
void Print(GNN_Data &d, std::string txt="")
Definition
TMVA_SOFIE_GNN_Application.C:59
tutorials
dataframe
df035_RDFFromPandas.py
ROOT v6-32 - Reference Guide Generated on Fri Nov 1 2024 15:09:38 (GVA Time) using Doxygen 1.9.8