1
이것이 파이썬 2.7에서 작동하는 이유는 무엇입니까?하지만 파이썬 3에서는 그렇지 않습니다. psycopg2를 사용하여 테이블에 값을 삽입하고 있지만 커서는 내 팬더 데이터 프레임에서 column2와 힘든 시간을 보내고 있습니다.파이썬 2와 파이썬 3의 차이점은 무엇입니까?
In [1]: df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 11565 entries, 0 to 11564
Data columns (total 3 columns):
column1 11565 non-null object
column2 11565 non-null int64
column3 11565 non-null object
dtypes: int64(1), object(2)
memory usage: 271.1+ KB
# Python 2.7
cur = conn.cursor()
# pass table values
vals = [cur.mogrify("(%s, %s, %s)", (x, y, z)) for x, y, z in zip(df['column1'], df['column2'],df['column3'])]
# Great!
-
# Python 3.5
cur = conn.cursor()
# pass table values
vals = [cur.mogrify("(%s, %s, %s)", (x, y, z)) for x, y, z in zip(df['column1'], df['column2'],df['column3'])]
<ipython-input-2-ee4818a2eb52> in <listcomp>(.0)
1 # pass table values
----> 2 vals = [cur.mogrify("(%s, %s, %s)", (x, y, z)) for x, y, z in zip(df['column1'], df['column2'],df['column3'])]
ProgrammingError: can't adapt type 'numpy.int64'
이 psycopg2 자체 또는 기본 파이썬 버전의 다른 버전과 관련이 있습니까? 감사.
이것은 적절한 대답 인 것 같습니다. [Psycopg2는 numpy int64 유형을 지원하지 않습니다.] (https://stackoverflow.com/questions/41449501/error-inserting-values-to-db-with-psycopg2-module). 또한 [관련 GitHub 페이지] (https://github.com/musically-ut/psycopg2_numpy_ext)를 참조하십시오. – Dan