繁体   English   中英

'float'对象没有属性'astype'

[英]'float' object has no attribute 'astype'

我试图在数据框的列中找到中值。 我得到的中位数是浮点型,但我需要整数格式。

c_med = round(df['count'].median().astype(int))

c_med = round(df['count'].median()).astype(int)

以上两种类型都给我这个错误。 如果astype(int) ,那么答案是正确的。

错误

Traceback (most recent call last):
  File "all_median.py", line 16, in <module>
    c_med = round(df['count'].median()).astype(int)
AttributeError: 'float' object has no attribute 'astype'

round函数之后,您将不再处于Pandas API中。

您必须像这样铸造价值

c_med = int(round(df['count'].median()) 

我对熊猫不太熟悉,但是您可以尝试

c_med = df['count'].median().round().astype(int)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM