Reputation: 807
When I try to run the following
df['ln_returns'] = np.log(df['Close_mid']/df['Close_mid'](1))
I get the error
'Series' object is not callable
When checking df.dtypes i get:
0
Close_mid float64
Close_large float64
Close_small float64
dtype: object
And when checking
print(type(df.Close_mid))
<class 'pandas.core.series.Series'>
How do I solve this ambiguity? I'm trying to calculate the logarithmic change between to periods
Upvotes: 0
Views: 3770
Reputation: 31011
The source of this error is that you wrote df['Close_mid'](1)
.
In this case Pandas acts as follows:
df['Close_mid']
(a column of your DataFrame),If you want to divide each element of this column by its first element, write:
df['Close_mid']/df['Close_mid'].iloc[0]
(note that in a Series the numeration of elements starts just from 0).
If you want to refer to the previous/next element, use shift().
Upvotes: 2
Reputation: 88
What are you trying by adding "(1)"?
Try this:
df['ln_returns'] = np.log(df['Close_mid']/df['Close_mid'])
Upvotes: 0
Reputation: 184
What you have is a Series of float64 type values. There is no ambiguity.
df['Close_mid']
is a Series and is not callable. Trying to call it like so df['Close_mid'](1)
raises the error.
Maybe you can elaborate on what you are trying to do with calling with (1)
.
Upvotes: 1