Python TypeError: ‘DataFrame’ object is not callable (2 Examples)
In this post, I’ll demonstrate how to handle the “TypeError: ‘DataFrame’ object is not callable” in the Python programming language.
Example Data
import pandas as pd # Import pandas |
import pandas as pd # Import pandas
my_df = pd.DataFrame({'A':range(10, 17), # Constructing a pandas DataFrame 'B':[1, 8, 3, 5, 7, 9, 1], 'C':range(28, 21, - 1)}) print(my_df) # A B C # 0 10 1 28 # 1 11 8 27 # 2 12 3 26 # 3 13 5 25 # 4 14 7 24 # 5 15 9 23 # 6 16 1 22 |
my_df = pd.DataFrame({'A':range(10, 17), # Constructing a pandas DataFrame 'B':[1, 8, 3, 5, 7, 9, 1], 'C':range(28, 21, - 1)}) print(my_df) # A B C # 0 10 1 28 # 1 11 8 27 # 2 12 3 26 # 3 13 5 25 # 4 14 7 24 # 5 15 9 23 # 6 16 1 22
Example 1: Replicating the TypeError: ‘DataFrame’ object is not callable
my_df('B').var() # Parantheses do not work # TypeError: 'DataFrame' object is not callable |
my_df('B').var() # Parantheses do not work # TypeError: 'DataFrame' object is not callable
Example 2: Fixing the TypeError: ‘DataFrame’ object is not callable
my_df['B'].var() # Square brackets work fine # Out[16]: 10.80952380952381 |
my_df['B'].var() # Square brackets work fine # Out[16]: 10.80952380952381
Related Tutorials & Further Resources
Here, you may find some additional resources on topics such as groups, counting, dates, and variables: