【发布时间】:2015-12-16 06:49:55
【问题描述】:
我正在尝试将 Pandas 数据框写入 MySQL 数据库,并使用了以下代码:
engine = sqlalchemy.create_engine("mysql+pymysql://root:password@localhost/skills?charset=utf8mb4")
connection = engine.connect
dataframe.head().to_sql('indeed_resumes', engine, flavor='mysql', if_exists='replace',index=True)
但是,我收到以下错误:
InternalError: (1366, "Incorrect string value: '\\xE1\\xBB\\x99i\\x0AO...' for column 'work' at row 5")
MySQL表的数据类型如下:
mysql> desc indeed_resumes;
+-----------+------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+------------+------+-----+---------+-------+
| index | bigint(20) | YES | MUL | NULL | |
| certs | text | YES | | NULL | |
| contact | text | YES | | NULL | |
| education | text | YES | | NULL | |
| headline | text | YES | | NULL | |
| info | text | YES | | NULL | |
| skills | text | YES | | NULL | |
| summary | text | YES | | NULL | |
| updated | text | YES | | NULL | |
| work | text | YES | | NULL | |
+-----------+------------+------+-----+---------+-------+
10 rows in set (0.00 sec)
我的数据包含很长的字符串(有时大约 3000 个字符),因此这可能会导致错误。有什么建议吗?
【问题讨论】:
标签: mysql pandas sqlalchemy