pandas.read_sql 处理速度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22874420/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 21:53:55  来源:igfitidea点击:

pandas.read_sql processing speed

pythonpandas

提问by Yann

I need for further processing the result set of a MySQL query as a dataframe. The SQL table contains about 2 million rows and 12 columns (Data size = 180 MiB). I'm running OS X 10.9 with 8 GB memory. Is it normal that pandas.read_sqltakes more than 20 secs to return the dataframe? How to implement a chunk size option like in pandas.read_csv?

我需要进一步处理 MySQL 查询的结果集作为数据帧。SQL 表包含大约 200 万行和 12 列(数据大小 = 180 MiB)。我正在运行具有 8 GB 内存的 OS X 10.9。pandas.read_sql需要超过 20 秒才能返回数据帧是否正常?如何在pandas.read_csv 中实现块大小选项?

Edit:Python 2.7.6, pandas 0.13.1

编辑:Python 2.7.6,Pandas 0.13.1

采纳答案by Adrien Pacifico

Pandas documentationshows that read_sql()/read_sql_query()takes about 10 times the time to read a file compare to read_hdf()and 3 times the time of read_csv().

Pandas的文件显示,read_sql()/read_sql_query()需要约10倍的时间来阅读比较文件read_hdf()和3倍的时间read_csv()

The read_sql()has now a chunk-size argument ( see the documentation)

read_sql()现在有一个块大小的参数(见文档