Python在导入数据到mysql是,报错了:
# -*- coding:utf-8 -*-
import sys
import MySQLdb
import tushare as ts
conn=MySQLdb.Connection
(
host="localhost",
user="root",
passwd="root",
charset="UTF8"
)
conn.select_db('test')
T = ts.get_latest_news(top=80,show_content=True)
# 创建指针,并设置数据的返回模式为字典
cursor = conn.cursor(MySQLdb.cursors.DictCursor)
# 执行SQL
cursor.executemany("insert into page values (%s,%s,%s,%s,%s)", T)
# 关闭指针
cursor.close()
# 关闭数据库连接
conn.close()
报错信息:
line 370: b"htmlParseEntityRef: expecting ';'" (line 370)
Traceback (most recent call last):
File "C:/Users/Administrator/PycharmProjects/untitled/test.py", line 12, in
cursor.executemany("insert into page values (%s,%s,%s,%s,%s)", T)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\MySQLdb\cursors.py", line 270, in executemany
if not args:
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\generic.py", line 917, in __nonzero__
.format(self.__class__.__name__))
ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
用的是MySqldb模块。请大神指导下。