Python Forum

Full Version: A couple of questions about counts/value_counts and pandas?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
why does this work

df[df['TotalPayBenefits']== df['TotalPayBenefits'].max()]
but this gives an error

df[df['TotalPayBenefits'].max()]
Error:
--------------------------------------------------------------------------- During handling of the above exception, another exception occurred: KeyError Traceback (most recent call last) <ipython-input-24-d77051c168c8> in <module> ----> 1 df[df['TotalPayBenefits'].max()] KeyError: 567595.43
while Key Error is kind of my answer but it doesnt give me the name it corresponds with the value

now for count and value counts

df[df['AM or PM']=='AM'].value_counts()
why does this give off an error

Error:
AttributeError: 'DataFrame' object has no attribute 'value_counts'
while value_counts is definitely an attribute

and

df['AM or PM'].value_counts()
value counts work just fine here