import psycopg2 import pandas as pd print(psycopg2.apilevel) connector = psycopg2.connect( host="localhost", database="postgres", user="samplex", port=5432, password="xxxxx") connection = psycopg2.connect(connector) sql = "SELECT id FROM Table1" df = pd.read_sql(sql, connection) print("finish!") connection.close()
以上のようなコードでsqlの結果のデータフレーム化をしたいのですが
Expected bytes or unicode string, got psycopg2.extensions.connection instead
というようなエラーが出たので
connection = psycopg2.extensions.connect(connector)
に書き換えてやってみたところ
module 'psycopg2.extensions' has no attribute 'connect'
というようなエラーの連鎖に陥ってしまい困っております
ちなみに「id」はすべてint型です
宜しくお願い致します
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/09/16 17:02
2018/09/16 17:19
2018/09/16 17:31