简体   繁体   English

使用轴时 count() 中出现意外的关键字错误

[英]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.

相关问题 在 Eve-SQLAlchemy 中使用 WHERE 时出错:TypeError: find() got an unexpected keyword argument 'perform_count' - Error when using WHERE in Eve-SQLAlchemy: TypeError: find() got an unexpected keyword argument 'perform_count' 类型错误:<lambda> () 使用 apply 后跟 groupby 时出现意外的关键字参数“axis” - TypeError: <lambda>() got an unexpected keyword argument 'axis' when using an apply followed by a groupby 使用映射器时,pandas DataFrame.rename 意外的关键字参数“axis” - pandas DataFrame.rename unexpected keyword argument "axis" when using mapper 我正在使用 google colab,一切都是最新的,但仍然出现此错误 TypeError: drop() got an unexpected keyword argument 'axis' - I am using google colab, everything is up to date and still get this error TypeError: drop() got an unexpected keyword argument 'axis' 在构造函数中使用** kwargs时出现意外的关键字参数 - Unexpected keyword argument when using **kwargs in constructor 千层面-意外的关键字错误 - lasagne - unexpected keyword error 加载时出错 tensorflow model - TypeError: __init__() got an unexpected keyword argument 'axis' - Error while loading tensorflow model - TypeError: __init__() got an unexpected keyword argument 'axis' scipy.stats rankdata:错误“rankdata()得到了一个意外的关键字参数'轴'” - scipy.stats rankdata : error "rankdata() got an unexpected keyword argument 'axis'" Django:尝试使用正确参数创建时出现意外关键字错误 - Django: Unexpected keyword error when trying to create with correct parameters Python 解压 matplotlib 图时出现“意外的关键字参数‘回调’”错误 - Python error "unexpected keyword argument 'callbacks'" when unpickling matplotlib figure
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM