Skip to content

BUG: why in scipy.integrate.trapz(y,x) using x,y from pd.read_csv does not give the right answer #3992

saullocastro opened this Issue Jun 22, 2013 · 2 comments

2 participants


Please, refer to this question in StackOverflow for more details:

The OP reads a csv using:

data_df = pd.read_csv("example.csv", sep="\t", index_col=0, names=["test"])

And when doing integration using the "Index" object at data_df.index it does not work, but works with data_df.index.values,,,,
Is it a bug?
Thank you!

jreback commented Jun 22, 2013

There is some indexing going on under the in trapz that does not play nice with an object dtyped array (which is how pandas keeps these types of indices). This is not a bug, more of scipy accepting values which in reality should be coerced to floats; also this will be quite slow using the direct index lookup; float indices are not a good idea in general. see for a nicer solution


Thank you for your answer!
When we take: index.values it also returns an array of objects... but the objects are floats in this case... that may be the case why it works!
Should I close this issue?

@jreback jreback closed this Jun 23, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.