【发布时间】:2017-04-12 02:13:08
【问题描述】:
我在 pandas 数据框 df 中有一个表格。
product_id_x product_id_y count date
0 288472 288473 1 2016-11-08 04:02:07
1 288473 2933696 1 2016-11-08 04:02:07
2 288473 85694162 1 2016-11-08 04:02:07
我想把这张表保存在mysql数据库中。
我正在使用 MySQLdb 包。
import MySQLdb
conn = MySQLdb.connect(host="xxx.xxx.xx.xx", user="name", passwd="pwd", db="dbname")
df.to_sql(con = conn, name = 'sample_insert', if_exists = 'append', flavor = 'mysql', index = False)
我使用此查询将其放入我的数据库中。
但我遇到了错误。
ValueError: database flavor mysql is not supported
我的数据类型是所有列的 str。
type(df['product_id_x'][0]) = str
type(df['product_id_y'][0]) = str
type(df['count'][0]) = str
type(df['date'][0]) = str
我不想使用 sqlalchemy 或其他软件包,谁能告诉我这里的错误是什么。 提前致谢
【问题讨论】:
标签: python python-2.7 python-3.x pandas