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

Closed
saullocastro opened this Issue Jun 22, 2013 · 2 comments

2 participants

@saullocastro

Please, refer to this question in StackOverflow for more details:
http://stackoverflow.com/q/17252024/832621

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!
Saullo

@jreback
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 http://pandas.pydata.org/pandas-docs/dev/cookbook.html#computation for a nicer solution

@saullocastro

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?
Greetings

@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.