gpt4 book ai didi

python - Pandas 读取 sql 整数变成 float

转载 作者:太空狗 更新时间:2023-10-29 21:39:09 24 4
gpt4 key购买 nike

我遇到一个问题,当我使用pandas读取Mysql表时,一些列(见'to_nlc')以前是整数变成了 float (之后自动添加.0)。任何人都可以弄清楚吗?还是一些猜测?非常感谢!

enter image description here enter image description here enter image description here

最佳答案

问题是您的数据包含 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.

关于python - Pandas 读取 sql 整数变成 float ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37796916/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com