2017-09-18 6 views
1

상당히 간단한 작업을 시도하고 있지만 odo이 손상되었거나이 패키지의 컨텍스트에서 datashapes의 작동 방식을 이해할 수 없습니다.AWS에서 CSV -> postgres를로드하기 위해 odo를 사용합니다.

CSV 파일 :

email,dob 
[email protected],1982-07-13 
[email protected],1997-01-01 
... 

코드 :

from odo import odo 
import pandas as pd 

df = pd.read_csv("...") 
connection_str = "postgresql+psycopg2:// ... " 

t = odo('path/to/data.csv', connection_str, dshape='var * {email: string, dob: datetime}') 

오류 : 나는 DataFrame에서 직접 이동하려고하면 그것은 동일한 오류의

AssertionError: datashape must be Record type, got 0 * {email: string, dob: datetime} 

-> 포스트그레스 :

t = odo(df, connection_str, dshape='var * {email: string, dob: datetime}') 

문제를 해결하지 못하는 몇 가지 다른 점은 1) CSV 파일에서 헤더 행을 제거하고 2) var을 DataFrame의 실제 행 수로 변경합니다.

내가 뭘 잘못하고 있니?

+0

당신이 pd.to_sql를 시도? csv를 포스트그레스 테이블에 저장하려고하는 것처럼 보입니까? https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_sql.html – wkzhu

+0

예, 정말 느립니다. 'odo'는 postgres의 복사본 내부 구조를 사용하여 훨씬 더 빠르게 처리 할 수 ​​있습니다 : http://odo.pydata.org/en/latest/perf.html – lollercoaster

+0

''odo'에 익숙하지 않지만 할 수 있습니다. 빠른로드 자신 https://stackoverflow.com/questions/41875817/write-fast-pandas-dataframe-to-postgres/ – Michael

답변

0

connection_str에 테이블 이름이 있습니까? 그것은 비슷한 문제가 있지만 sqlite 데이터베이스를 만났을 때 나를 위해 고정.

이 될해야 뭔가 같은 :

connection_str = "postgresql+psycopg2://your_database_name::data" 
t = odo(df, connection_str, dshape='var * {email: string, dob: datetime}') 

'connection_str'에서 '데이터'새 테이블 이름입니다

.

은 참조 :

python odo sql AssertionError: datashape must be Record type, got 0 * {...}

https://github.com/blaze/odo/issues/580