Why is 'DataFrame' object not callable

I have used Python for years and am trying to get more familiar with Pandas. I keep finding things that do not seem Pythonic to me. In this case, I want to use the largest value from my DataFrame to build a range object but I find that I cannot make an integer to feed to the range() function from the float returned as the maximum value of my DataFrame. As a minimal reproducible example, here is some code illustrating the error.

# Create a DataFrame  pairs = pd.DataFrame({'Pair': ['A-B', 'A-C'], 'Distance': [54.3, 9009.122894715296]})  # Select the max pairs['Distance'].max() 9009.122894715296  # Check the type type(pairs['Distance'].max()) <class 'float'>  # Make an integer to use in range function int(pairs['Distance'].max())  TypeError: 'DataFrame' object is not callable 

I have never had an issue converting a float to an integer so I do not understand why a) it is calling it a DataFrame object when it is clearly a float and b) it cannot convert this float to an integer. Hopefully someone has some knowledge of the operations that lead to this error.

Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.