mysql显示nan_Python将dataframe连接到MySQL时出现NaN[mysqlconnector]

我使用Python将pandas数据帧中的一些列插入MySQL。我用的是熊猫15.2。以及mysql.connector. 在import mysql.connector

cte = mysql.connector.connect(user=xxxxxxxxx, password=xxxxxxx, host=xxxxxx)

cursor = cte.cursor()

for index, row in pets.iterrows():

home_pets = (row['cats'], row['dogs'], row['goldfish'], row['rabbits'], row['mice'], row['parrots'])

add_pets = """

INSERT INTO pets

(cats, dogs, goldfish, rabbits, mice, parrots)

VALUES (%s, %s, %s, %s, %s, %s)

"""

cursor.execute(add_pets, home_pets)

cte.commit()

我的一个整型列中有“NaN”值。我刚刚添加了这一点,因为之前一切正常,所以我确信这是导致问题的专栏。这是一个varchar(5)(was int(5))列,未设置为“not NULL”。

编辑:此列(鹦鹉)包含数字0到5作为响应。它还有“NaN”,即受访者没有回答问题。在

尝试在表中插入数据时收到以下错误消息:

^{pr2}$

我希望将int列保留为int,如果可能的话,不必将其更改为object(然后每次从MySQL数据库将数据读入Python时都要来回地修改)。这可能吗?感谢你的帮助。在