写入MySQL资料库时,ValueError DataFrame的真值含糊

时间:2019-01-01 14:10:03

标签: python mysql pandas mysql-python valueerror

我有一个看起来像这样的Pandas数据框:

record_id    date          name            url                            title         company

1            2018-12-31    John Doe        http://www.johndoe.com        consultant    john's consulting co
2            2018-12-31    Jane Smith      http://www.janesmith.com      engineer      engineers ltd
3            2018-12-31    Tim Rogers      http://www.timrogers.com      doctor        medical doctors inc.
4            2018-12-31    Charles Jones   http://www.charlesjones.com   electrician   electricians company
5            2018-12-31    Shirley Miller  http://www.shirleymiller.com  veterenarian  animal rescue

所有列的dtype为“对象”。

我正在尝试使用以下代码段将此表作为新行插入到MySQL数据库中(利用Python的MySQL连接器):

    cursor.executemany(
        "INSERT IGNORE INTO person_info(`record_id`, `date`, `name`, `url`, `title`, `company`) "
        "VALUES (%s, %s, %s, %s, %s, %s)",
        person_info_table)

但是,这会产生以下错误消息:

Traceback (most recent call last):
File "E:\Projects\Headcount\headcount_streamlined\headcount_functions.py", line 176, in insert_into_db location_info_table)
File "C:\ProgramData\Anaconda3\lib\site-packages\mysql\connector\cursor.py", line 645, in executemany
if not operation or not seq_params:
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\generic.py", line 1576, 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().`

不知道这是怎么回事,为什么会抛出此错误消息-有人能提供一些见识吗?

0 个答案:

没有答案