soldpricemean = '{:,}'.format(bedbath_df.sold_price.mean().astype(int))
由于某些原因,这种格式化浮点数的方式在我写的一个程序中有效,但不是我目前正在处理的程序。我得到的错误是:
AttributeError:“float”对象没有属性“”astype“”
有人能解释一下为什么会这样吗?谢谢!
发布于 2018-06-09 07:15:15
问题不在于格式。正如错误清楚地指出的那样,float
对象没有astype
属性。我假设你是从一种不同的语言获得的,但在Python中,这不是你改变类型的方式。
如果要将float
转换为int
,则语法为int(float)
,而不是float.astype(int)
。您需要代码soldpricemean = '{:,}'.format(int(bedbath_df.sold_price.mean()))
https://stackoverflow.com/questions/50769396
复制相似问题