简体   繁体   English

Python的麻烦 - Jupyter笔记本上的Postgresql | Mac OSX

[英]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.

相关问题 Jupyter Notebook中的适用于Python 3的ModuleNotFoundError,但不适用于Python 2(Mac OSX) - ModuleNotFoundError in Jupyter Notebook for Python 3 but not Python 2 (Mac OSX) m1 mac,python 在 matplotlib 和 jupyter 笔记本中使用 osx 作为后端时断言失败和崩溃 - m1 mac, python assertion failure and crashes when using osx as backend in matplotlib & jupyter notebook Jupyter无法识别Python Mac OSX(内核错误) - Jupyter does not recognize Python Mac OSX (Kernel error) 尝试使用 Python Jupyter Notebook 将带有地理标记的推文流式传输到 PostgreSQL 时出现问题 - Problem trying to stream geotagged tweets into PostgreSQL using Python Jupyter Notebook MAC os上的jupyter笔记本python:“没有名为Orange的模块” - jupyter notebook python on MAC os : “no module named Orange” jupyter notebook 无法在 Mac 上运行 - jupyter notebook cannot run on Mac Anaconda jupyter笔记本电脑无法在Mac上启动 - Anaconda jupyter notebook will not start on Mac 如何在 mac 上安装 jupyter notebook? - How to install jupyter notebook on mac? 我可以打开 jupyter 笔记本,但无法在 Mac 上运行带有 python 脚本的笔记本 - I can open a jupyter notebook, but I cannot run the notebook with python script in it on my Mac 无法在OSX上启动Jupyter Notebook- - Can't launch Jupyter Notebook on osx -
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM