Pandas array to TGraph

Dears rooters,

I’m having a problem to create a TGraph from pandas dataframe.
This is the part of the code, where I read the data with pandas, I convert the 2 columns in array in order to pass them to the TGraph:

import pandas as pd
df=pd.read_csv(csv_off, sep=’\t’)

n= len(df[‘HV1’])
x= df[‘HV1’].values
y= df[‘EFF1’].values

w= TGraph(n,x,y)

canvas= TCanvas()


The error that I got is:
Error in <TGaxis::PaintAxis>: length of axis is 0

I check the data reading and it is ok

thanks in advance


not sure what the cause could be. Anyway, perhaps the best solution would be to use RDataFrame directly in ROOT:

import ROOT
MakeCsvDataFrame = ROOT.ROOT.RDF.MakeCsvDataFrame
# here it depends if you have headers for your columns or not
df = MakeCsvDataFrame("myTextInput", hasHeaders, "\t")
# again here we assume you do not have headers
g = df.Graph("Col0", "Col1")
canvas= ROOT.TCanvas()


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.