问题是您的数据包含NaN值,因此int会自动转换为float.
我想你可以查看NA类促销:
当通过reindex或其他方式将NAs引入现有Series或DataFrame时,布尔和整数类型将被提升为不同的dtype以存储NA.这些表总结如下:
Typeclass Promotion dtype for storing NAs
floating no change
object no change
integer cast to float64
boolean cast to object
Run Code Online (Sandbox Code Playgroud)
虽然这似乎是一个沉重的权衡,但在实践中我发现很少有这种情况在实践中存在.下一节中对动机的一些解释.