[英]Troubles with Python - Postgresql on Jupyter Notebook | Mac OSX
I'm currently develop a Jupyter notebook with Python code, in Mac OSX Mojave 10.14. 我目前在Mac OSX Mojave 10.14中开发了一个带有Python代码的Jupyter笔记本。 I'm using Psycopg2 to get data from PostgreSQL to Python Dataframe. 我正在使用Psycopg2从PostgreSQL获取数据到Python Dataframe。
The problem is the code works fine in Win 10, in two ways, but I not get data from the same query in Mac OSX. 问题是代码在Win 10中运行良好,有两种方式,但我没有从Mac OSX中的同一查询中获取数据。
I don't get any error, I just get an empty Dataframe. 我没有得到任何错误,我只是得到一个空的Dataframe。 Nothing more. 而已。 No error, no warning. 没有错误,没有警告。
Anyone have been in the same trouble? 有人遇到过同样的麻烦吗?
The used code is below: 使用的代码如下:
First option: 第一种选择:
cursor = conn.cursor()
query = """select * from table"""
cursor.execute(query)
data = data.append(cursor.fetchall())
data.columns = [desc[0] for desc in cursor.description]
Second option: 第二种选择:
data= pd.DataFrame()
for chunk in pd.read_sql("""select * from table""", con=conn, chunksize=5000):
data= data.append(chunk)
I expect a Dataframe with the data from PostgreSQL. 我期待一个带有PostgreSQL数据的Dataframe。
The problem was that I had a '%%time' statement before the query, to get the execute time of the cells. 问题是我在查询之前有一个'%% time'语句来获取单元格的执行时间。 Funny. 滑稽。 It seems in Mac OSX doesn't work with a piece of code below. 在Mac OSX中似乎无法使用下面的一段代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.