Wednesday, May 29, 2013

A little funkyness with Pandas index

Problem:

I made a Pandas DataFrame
df
with a float index. Everything worked fine, including
df.plot()
But when I tried to do
pylab.exp(df.index.values)
I got the mysterious error
AttributeError: exp

Explanation:

It turns out that Pandas' index is restricted to int64 and 'object' and so
df.index.values
returns an
'object'
type array with exp can't interpret. We need to explicitly cast it as
'float'
to get things to work :
pylab.exp(df.index.values.astype('float'))

No comments:

Post a Comment