Python Forum
A couple of questions about counts/value_counts and pandas?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A couple of questions about counts/value_counts and pandas?
#1
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Similarity function for couple system sunnydayxo 1 2,113 Apr-16-2021, 07:11 AM
Last Post: MH90000

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020