解决方法
问题是您的数据包含NaN值,因此int会自动转换为float.
我想你可以查看NA type promotions:
When introducing NAs into an existing Series or DataFrame via reindex or some other means,boolean and integer types will be promoted to a different dtype in order to store the NAs. These are summarized by this table:
Typeclass Promotion dtype for storing NAs floating no change object no change integer cast to float64 boolean cast to object
While this may seem like a heavy trade-off,in practice I have found very few cases where this is an issue in practice. Some explanation for the motivation here in the next section.