Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Python
  3. Question
Python

Python error "'Series' object is not callable "

Asked by Coleman Garvin Apr 13, 2021 3.0K views 2 answers
Share

About this question

This line:

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

Gives the following error:

'Series' object is not callable

Your answer

2 Answers

Ranjana Admin JanBask Expert Latest answer

Answered on Jun 6, 2024

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.












Was this helpful?

More Python discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Python Blogs

Guides, tips and career advice on Python from JanBask experts.