使用扩展数据类型时,value_counts(normalize=True)失败。例如,当创建包含pd.NA的int8系列时,通常会使用Int8扩展数据类型,但会出现错误:AttributeError: 'IntegerArray' object has no attribute 'sum'。解决办法是什么
# 1) works if you're ok with dropping NA
pd.Series([1,pd.NA],dtype='Int8').dropna().astype(int).value_counts(normalize=True)
# 2) works if you're ok with switching to a non-extension datatype such as float
pd.Series([1,pd.NA],dtype='Int8').astype(float).value_counts(normalize=True)
# 3) The issue may be fixed in a future versions of pandas. Try using a pandas version >= 1.1
这被认为是一个回归错误,请参见GH33317。好消息是,这是固定在熊猫1.1
更多示例
以下各项可用于解决该问题:
相关问题 更多 >
编程相关推荐