Typeerror: ‘dataframe’ object is not callable

When you are working with Pandas library one of the errors you can not avoid is Typeerror: ‘dataframe’ object is not callable.

Typically this error occurs when we use the parenthesis ( ) instead of square brackets [ ] in creating or accessing dataframe column.

In this article, we will explore how this error occurs, how to fix it, and how to prevent it from occurring in the future.

What is Typeerror: ‘dataframe’ object is not callable?

This error typically occurs in Python programming when you attempt to call a method or function on a DataFrame object, but mistakenly use parentheses ( ) instead of square brackets [ ].

Here is an example of a Dataframe of object as follows:

import pandas as pd

#create DataFrame
df = pd.DataFrame({'Name': ['John', 'Emily', 'Charlie', 'David'],
        'Age': [25, 30, 20, 40],
        'Gender': ['Male', 'Female', 'Male', 'Male'],
        'Salary': [50000, 60000, 45000, 70000]})

#view DataFrame
print(df)

This will output the following:

      Name  Age  Gender  Salary
0     John   25    Male   50000
1    Emily   30  Female   60000
2  Charlie   20    Male   45000
3    David   40    Male   70000

How this ‘dataframe’ object is not callable occur

Given in the example above, if we want to display the values in Name column we should specify it in the print() function.

Here is the example code.

import pandas as pd

#create DataFrame
df = pd.DataFrame({'Name': ['John', 'Emily', 'Charlie', 'David'],
        'Age': [25, 30, 20, 40],
        'Gender': ['Male', 'Female', 'Male', 'Male'],
        'Salary': [50000, 60000, 45000, 70000]})

#view DataFrame
print( df('Name') )

If we run the code above, this will output an error since we wrongly used parenthesis in accessing the column.

Traceback (most recent call last):
  File "C:\Users\Windows\PycharmProjects\pythonProject1\main.py", line 10, in <module>
    print( df('Name') )
TypeError: 'DataFrame' object is not callable

Now let’s move to the next section where we are going to fix this error.

How to fix Typeerror: ‘dataframe’ object is not callable

One way to solve this error is just to replace the parenthesis ( ) with square brackets [ ] when accessing the column.

Here is an example, suppose we want to display the values in the Name column.

import pandas as pd

#create DataFrame
df = pd.DataFrame({'Name': ['John', 'Emily', 'Charlie', 'David'],
        'Age': [25, 30, 20, 40],
        'Gender': ['Male', 'Female', 'Male', 'Male'],
        'Salary': [50000, 60000, 45000, 70000]})

#view DataFrame
print( df['Name'] )

Here is the output:

0       John
1      Emily
2    Charlie
3      David
Name: Name, dtype: object

Use the dot (.) notation

Alternatively, we can also use the dot (.) notation instead of brackets while accessing the dataframe column.

import pandas as pd

#create DataFrame
df = pd.DataFrame({'Name': ['John', 'Emily', 'Charlie', 'David'],
        'Age': [25, 30, 20, 40],
        'Gender': ['Male', 'Female', 'Male', 'Male'],
        'Salary': [50000, 60000, 45000, 70000]})

#view DataFrame
print( df.Salary)

Output:

0    50000
1    60000
2    45000
3    70000
Name: Salary, dtype: int64

Tips to Avoid this error

To avoid the “TypeError: ‘DataFrame’ object is not callable” error in Python, you can follow these tips:

  1. Use square brackets [ ] to access elements in a DataFrame, rather than parentheses ().
  2. Check for any typos or syntax errors in your code, as they can lead to this error.
  3. Make sure you are using the correct variable names and data types when calling functions or methods on your DataFrame.
  4. Avoid using the same variable name for both a DataFrame object and a function, as this can cause confusion and lead to this error.
  5. Use descriptive variable names to help prevent naming conflicts and make your code more readable.

FAQs

What causes the “TypeError: ‘DataFrame’ object is not callable” error?

The error occurs when you try to call a DataFrame object as if it were a function, usually by using parentheses () instead of square brackets [ ] to access a specific element in the DataFrame.

How can I fix the “TypeError: ‘DataFrame’ object is not callable” error?

To fix the error, make sure you are using square brackets [ ] to access elements in the DataFrame, check for any syntax errors or typos in your code.

Also, use the correct variable names and data types, and avoid using the same variable name for both a DataFrame object and a function.

Conclusion

In conclusion, the TypeError: ‘DataFrame’ object is not callable error in Python occurs when a DataFrame object is called as if it were a function. Usually by using parentheses ( ) instead of square brackets [ ] to access a specific element in the DataFrame.

It is important to be consistent and careful when working with DataFrames to avoid this error and ensure that your code runs smoothly.

We hope that this guide has helped you resolve this error and get back to coding.

If you are finding solutions to some errors you might encounter we also have  TypeError: not supported between instances of ‘str’ and ‘int’

Thank you for reading!

Frequently Asked Questions

What is Python TypeError and what causes it?

TypeError is raised when an operation is applied to an object of the wrong type. Common patterns: calling a non-callable object, adding incompatible types (str + int), passing the wrong number of arguments, or accessing attributes on a NoneType. Each TypeError message names the operation and expected vs actual types, the fix is almost always to convert types explicitly (int(), str()) or fix the wrong variable assignment.

How do I quickly debug a Python TypeError?

Three steps: (1) Read the full error message, it names the exact operation and types involved. (2) Print the type of every variable in that line: print(type(var1), type(var2)). (3) Check what the function expected vs what you passed. Most TypeError fixes are 1-line type casts or fixing a variable that became None unexpectedly.

Should I catch TypeError or let it propagate?

For internal code, let TypeError propagate, it’s almost always a real bug (wrong type passed). For boundary code (parsing user input, third-party API responses), catch TypeError + ValueError together: try: parsed = int(value) except (TypeError, ValueError): parsed = 0. Catching internal TypeErrors hides bugs.

How do I prevent TypeError in production?

Three patterns: (1) Use type hints (def add(a: int, b: int) -> int) and check with mypy / pyright in CI. (2) Validate inputs at boundaries (Pydantic for FastAPI, DRF serializers for Django). (3) Default values that match expected types (return 0 not None for numeric functions). Static typing catches 80% of TypeErrors before runtime.

Where can I find more TypeError fixes?

Browse the TypeError reference hub for 220+ specific TypeError fixes. For broader Python debugging, see the Python Tutorial hub. For related error types, see ValueError and AttributeError guides.

Glay Eliver

Programmer & Technical Writer at PIES IT Solution

Glay Eliver is a programmer and writer at PIES IT Solution, author of over 600 tutorials at itsourcecode.com. Specializes in JavaScript tutorials, Microsoft Office how-tos (Excel, Word, PowerPoint), and Python error debugging covering ImportError, TypeError, AttributeError, ModuleNotFoundError, and JavaScript ReferenceError. Authored several of the site’s highest-traffic Excel and MS Office reference articles.

Expertise: JavaScript · MS Excel · MS Word · MS PowerPoint · Python · Python ImportError · Python TypeError · Python AttributeError · ModuleNotFoundError · JavaScript ReferenceError · Pygame  · View all posts by Glay Eliver →