【发布时间】: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