상당히 간단한 작업을 시도하고 있지만 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의 실제 행 수로 변경합니다.
내가 뭘 잘못하고 있니?
당신이 pd.to_sql를 시도? csv를 포스트그레스 테이블에 저장하려고하는 것처럼 보입니까? https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_sql.html – wkzhu
예, 정말 느립니다. 'odo'는 postgres의 복사본 내부 구조를 사용하여 훨씬 더 빠르게 처리 할 수 있습니다 : http://odo.pydata.org/en/latest/perf.html – lollercoaster
''odo'에 익숙하지 않지만 할 수 있습니다. 빠른로드 자신 https://stackoverflow.com/questions/41875817/write-fast-pandas-dataframe-to-postgres/ – Michael