Reputation: 73
I'm getting the error:
count() got an unexpected keyword argument 'axis'
From what I've researched, this is caused by an outdated version of pandas, but when I run pd.__version__
I get version 1.2.3
Code where the error is occuring:
bdf = df.loc[df['Responsible Party'] == name]
bdf = bdf.sort_values('Date')
bdf['Patient'] = bdf['Patient'].str.replace(' ', '')
num_patients = bdf['Patient'].count(axis='columns')
Any ideas? I'm curious if this is some kind of PATH error but as far as I can tell there's no other older instalations of pandas on the system.
Upvotes: 0
Views: 1195
Reputation: 2129
DataFrame[<column name>]
returns the column values as a Pandas-Series
. Count function of Series doesn't have the axis
parameter like a DataFrame
.
To get total count of values in the column simply use count()
num_patients = bdf['Patient'].count()
To get count of unique values in the column use nunique()
num_patients = bdf['Patient'].nunique()
For practical applications I would recommend considering SeaBean's suggestion to not use names as unique identifiers
Upvotes: 1