【问题标题】:Why NAN values while fetching data?为什么在获取数据时使用 NAN 值?
【发布时间】:2019-10-22 20:49:04
【问题描述】:
from sqlalchemy import create_engine
import pymysql
import pandas as pd

db_connection_str='mysql+pymysql://username:pwd@Host/DB'
db_connection = create_engine(db_connection_str)

df = pd.read_sql('select * from tbl_store_inventory', con=db_connection)
print(df)

执行此代码后,我将获得所有列的 NAN 值。为什么?

【问题讨论】:

  • 你确定,还有一个不是 NULL 的结果。请在您的代码中添加错误处理stackoverflow.com/questions/30996401/…
  • 是的,我确定,我已经检查了 mysql 工作台,我正在那里获取数据。
  • 欢迎来到 StackOverflow。 tbl_store_inventory 是什么样的?如果您在不同的程序(如 DB IDE)中查看表,列中是否有条目?
  • 嘿!欢迎 :) 您使用过 read_sql(),我相信这是对 read_sql_table 和 read_sql_query 的包装。您提供了一个查询,据我了解 read_sql() 将使用 read_sql_query()。我认为这适用于正确确定要使用的数据类型的工作量较少。当您从 tbl_store_inventory 运行 select * 时,不妨试试 read_sql_table(table_name ='tbl_store_inventory', con= db_connection)?
  • 是的,有 4 列,StoreID、BatchID、数量、位置,是的,每一列都有各自的数据

标签: python mysql pandas sqlalchemy


【解决方案1】:

我想我是因为 read_sql() 而获得了 NAN 值,我使用了 read_sql_table() 并且得到了非 NAN 输出,当我对现有值使用 read_sql() 时,我也获得了 NAN,但现在之后对现有值使用 read_sql_table() 我没有得到任何 NAN 值。

【讨论】:

    猜你喜欢
    • 2022-01-11
    • 1970-01-01
    • 2023-03-14
    • 1970-01-01
    • 1970-01-01
    • 2015-02-18
    • 1970-01-01
    • 2020-06-19
    • 2020-03-12
    相关资源
    最近更新 更多