Python error "'Series' object is not callable "

1.5K    Asked by ColemanGarvin in Python , Asked on Apr 13, 2021

This line:

df['ln_returns'] = np.log(df['Close_mid']/df['Close_mid'](1))

Gives the following error:

'Series' object is not callable

Answered by Coleman Garvin

If you are facing typeerror: 'series' object is not callable error then the problem maybe that you are trying to call ma function on a series object which is not possible, but you can do it like this:

  df['ln_returns'] = np.log(df['Close_mid']/df['Close_mid'])


Your Answer

Answer (1)

The error "'Series' object is not callable" typically occurs in Python when you try to call a Pandas Series object as if it were a function. This can happen if you mistakenly use parentheses () instead of square brackets [] when trying to access elements of the Series.

Here's an example of how this error might occur:

  import pandas as pd# Creating a Pandas Seriesdata = {'a': 1, 'b': 2, 'c': 3}series = pd.Series(data)

# Trying to access an element using parentheses instead of square brackets

  value = series('a')  # Incorrect usage of parentheses

To fix this error, you should use square brackets to access elements of the Series:

  value = series['a']  # Correct usage with square brackets

This way, you're treating the Series object like a dictionary, where the keys are used to access the corresponding values.












5 Months

Interviews

Parent Categories