[英]Unexpected keyword error in count() when using axis
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根据我的研究,这是由 pandas 的过时版本引起的,但是当我运行
pd.__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.
我很好奇这是否是某种 PATH 错误,但据我所知,系统上没有其他较旧的 pandas 安装。
DataFrame[<column name>]
returns the column values as a Pandas-Series
. DataFrame[<column name>]
将列值作为Pandas-Series
返回。 Count function of Series doesn't have the axis
parameter like a DataFrame
. Series 的计数 function 没有
axis
参数,如DataFrame
。
To get total count of values in the column simply use count()
要获取列中值的总数,只需使用
count()
num_patients = bdf['Patient'].count()
To get count of unique values in the column use nunique()
要获取列中唯一值的计数,请使用
nunique()
num_patients = bdf['Patient'].nunique()
For practical applications I would recommend considering SeaBean's suggestion to not use names as unique identifiers对于实际应用,我建议考虑 SeaBean 的建议,不要使用名称作为唯一标识符
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.