- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 SQL 和 Pandas。遵循 sql queries 的 pandas 指南以及相关的sqlalchemy
engine specification guide
from sqlalchemy import create_engine
'''
example from sqlalchemy guide, engine_spec has the form of:
dialect+driver://user:password@host:port/name
where leaving out "+driver" defaults to whatever the SQLAlchemy choose for dialect
'''
my_engine_spec = 'mysql://user:password@host:port/name'
engine = create_engine(my_engine_spec)
data = pd.read_sql_table(table_name, engine, chunksize=10)
注意事项:
我限制chunksize
到10,表中有超过10条记录。这是为了测试以确保代码可以在不等待数据转储的情况下工作...但它仍然无法解决
我正在使用mysql
使用默认驱动程序,我经历了使用 python3+ 在 macOS 上安装它的痛苦
我等了 5 分钟多才终止脚本。
我可以使用具有相同规范的所选 SQL DB 可视化工具应用程序(例如 Sequel Pro)立即查看数据,因此假设变量 my_engine_spec
是正确的。
为什么这个问题需要这么长时间甚至没有解决?我怎样才能加快速度?
最佳答案
I limit chunksize to 10 and there are more than 10 records in the table.
Pandas 以 block 的形式读取整个表,每个 block 有 10 条或更少的记录。当您指定 chunksize
时,pandas.read_sql_table
将返回一个生成器。
data = pd.read_sql_table(table_name, engine, chunksize=10)
[data.__next__() for _ in range(1)] # only read one chunk, 10 records or less
I waited over 5 minutes before terminating the script.
read_sql_table
将读取整个表的所有记录。这意味着如果你想使用read_sql_table
一个非常大的表然后选择特殊列,与在mysql中完成它相比,你将花费更多的时间和内存。 为什么你花了这么长时间,这与你通过代码所做的事情相关,如果你只运行你的示例代码显示的内容,它应该很快(我已经尝试阅读0.5M条记录,但只需要几秒钟)
Why does this take so long or not even resolve?
如果您不需要所有记录,请使用 read_sql
或 read_sql_query
运行查询。因为MySQL做得很好。
关于python - pandas read_sql_table 永远不会解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53786513/
我正在尝试通过 python 访问我的 Oracle 11g(r2) Express Edition 数据库。我特别想从其中一个表 HISTORY_FULLNESS 创建一个 Pandas DataF
我正在尝试使用 SQL 和 Pandas。遵循 sql queries 的 pandas 指南以及相关的sqlalchemy engine specification guide from sqlal
我正在尝试将我的 Postgres 数据库中的表格读入 Python。表大约有 800 万行和 17 列,在数据库中的大小为 622MB。 我可以使用 psql 将整个表导出到 csv,然后使用 pd
我有一个使用 Pandas 的 read_sql,它工作正常。但是,当我尝试使用相同的逻辑在 Dask 下重新创建相同的数据框时。它给了我 NoSuchTableError。我确定该表存在于我的 SQ
尝试以下代码 alerts = df.read_sql_table('alerts', db_url, index_col='id', npartitions=16) 我收到以下错误: TypeErr
我使用了 MariaDB 服务器,并尝试连接并将数据放入 python 中的 pandas 数据帧中。 MariaDB 如下所示: CREATE DATABASE `fhem` DEFAULT CHA
我正在尝试将 SQLAlchemy 表达式与 dask 的 read_sql_table 结合使用,以降低通过连接和过滤几个不同的表创建的数据集。 documentation表明这应该是可能的。 (下
我正在尝试将 SQLAlchemy 表达式与 dask 的 read_sql_table 结合使用,以降低通过连接和过滤几个不同的表创建的数据集。 documentation表明这应该是可能的。 (下
我正在尝试从 postgres 中的表创建 dask 数据框。我想将 application_name = 'myapp' 作为标准传递用于监视和跟踪数据库事件。 但是当我尝试添加参数时,出现以下错误
我正在尝试使用 dask 中的 read_sql_table,但我遇到了一些与 index_col 参数相关的问题。我的 sql 表没有任何数值,我不知道要给 index_col 参数什么。 我在文档
我正在尝试使用以下代码从 PostgreSQL 表获取 DataFrame: import pandas from sqlalchemy.engine import create_engine eng
我正在使用df = dd.read_sql_table('mytable_name', 'connection_string',npartitions=10, index_col='id')创建一个
我是一名优秀的程序员,十分优秀!