【问题标题】:Pd.read_sql add zero to int number from table sql serverPd.read_sql 将零添加到表 sql server 中的 int 数
【发布时间】:2021-06-17 06:39:53
【问题描述】:

我想知道为什么 pandas.read_sql 在我的数据末尾添加 .zero ? 在 SQL Server 中,数据是用 int 表示的数字。

有人知道为什么吗?

当我查看数据类型时,它显示为 float64。

【问题讨论】:

    标签: python sql-server tkinter read-sql


    【解决方案1】:

    根据这个solution,发生这种情况是因为您的数据可能包含NaN 值,因此为了处理这个问题,int 数据类型会自动转换为float

    当通过重新索引或其他方式将 NA 引入现有 Series 或 DataFrame 时,boolean 和整数类型将被提升为不同的 dtype 以存储 NA。下表总结了这些:

    Typeclass   Promotion dtype for storing NAs
    floating    no change
    object      no change
    integer     cast to float64
    boolean     cast to object
    

    【讨论】:

      猜你喜欢
      • 2012-05-07
      • 1970-01-01
      • 2016-07-26
      • 2023-03-08
      • 1970-01-01
      • 2013-07-17
      • 2014-09-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多