Phi*_*ski 5 python-3.x pandas pandasql
我目前正在从 R 切换到 Python(anconda/Spyder Python 3)以进行数据分析。在 RI 中使用了很多 R sqldf。由于我擅长sql查询,我不想重新学习data.table语法。使用 R sqldf,我从来没有遇到过性能问题。
现在,在 Python 中我尝试使用 pandasql 一个简单的df = "SELECT * From table LIMIT 1"将永远持续 193k 行,19 列。
我试过 pysqldf 但我收到一个错误,说该表不存在,但它确实存在。
# -*- coding: utf-8 -*-
import pandas as pd
import pandasql
import pysqldf
#Data loading
orders = pd.read_csv('data/orders.csv',sep = ';')
###### PANDASQL ######
test = pandasql.sqldf("SELECT orders_id from orders LIMIT 1;",globals())
# Will last several minutes and use a lot of RAM
test = pandasql.sqldf("SELECT orders_id from orders LIMIT 1;",locals())
# Will last several minutes and use a lot of RAM
###### PYSQLDF ######
sqldf = pysqldf.SQLDF(globals())
test = sqldf.execute("SELECT * from orders LIMIT 1;")
#error
#Error for pysqldf
Traceback (most recent call last):
File "<ipython-input-12-30b645117dc4>", line 1, in <module>
test = sqldf.execute("SELECT * from orders LIMIT 1;")
File "C:\Users\p.stepniewski\AppData\Local\Continuum\anaconda3\lib\site-packages\pysqldf\sqldf.py", line 76, in execute
self._del_table(tables)
File "C:\Users\p.stepniewski\AppData\Local\Continuum\anaconda3\lib\site-packages\pysqldf\sqldf.py", line 117, in _del_table
self.conn.execute("drop table " + tablename)
OperationalError: no such table: orders
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?在“学习熊猫查询语法”之前更喜欢pandasql/pysqldf答案。
R 中的 Sqldf 在 i7/12G ram 笔记本电脑上处理多达 1000 万行的表的复杂查询。
谢谢 !
好的,刚刚找到解决方案。
| 归档时间: |
|
| 查看次数: |
2036 次 |
| 最近记录: |