【发布时间】:2016-04-20 20:48:57
【问题描述】:
我有这些 CSV 文件(从here 指向 zip 文件的顶部链接),我正试图将它们插入 Oracle 数据库。 使用以下代码时出现此错误。我尝试使用 utf-8 进行编码,但没有骰子...
UnicodeEncodeError: 'ascii' codec can't encode character '\xdf' in position 18:
ordinal not in range(128)
正在使用的代码:
import pandas as pd
from sqlalchemy import create_engine
import cx_Oracle as cx
pwd=input('Enter Password for server:')
engine = create_engine('oracle+cx_oracle://schema:'+pwd+'@server:1521/service_name')
df=pd.read_csv(r'path\data.csv',encoding='latin-1',index_col=0)
name='table1'
df.to_sql(name,engine,if_exists='append')
当我通过 pd.read_csv 打开 csv 文件时,它在我的 Jupyter 笔记本中运行良好。
【问题讨论】:
标签: oracle python-3.x pandas unicode