[英]Copy Pandas Dataframe to Postgres with odo
我想使用這個頂級python庫odo將數據從Pandas傳輸到我的postgres db。 它看起來很方便,但我無法使用它:(。
有人知道我想念的是什么。 一定是小東西.....
因此,我附帶以下代碼:
import odo, pandas
.....
odo(df, 'postgresql://postgres:password@localhost::mapping_ean_asin')
我得到了錯誤:
TypeError: 'module' object is not callable
預先感謝您的幫助 :)
解決我的問題:)!
SQL_STATEMENT = """ COPY %s FROM STDIN WITH
CSV
HEADER
DELIMITER AS ','
"""
my_file = open("/home.........csv")
def process_file(conn, table_name, file_object):
cursor = conn.cursor()
cursor.copy_expert(sql=SQL_STATEMENT % table_name, file=file_object)
conn.commit()
cursor.close()
connection = psycopg2.connect("dbname='postgres' user='postgres' host='localhost' password='password'")
try:
process_file(connection, 'my table', my_file)
finally:
connection.close()
我本來希望用odo與一行解決方案,但是我遇到了第二個錯誤.....
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.