将数据插入mysql数据库python时,整数值不正确

时间:2018-03-26 03:34:07

标签: python

我有这样的示例代码:

import csv
import MySQLdb

mydb = MySQLdb.connect(host='localhost', user='root', passwd='root', db='marbola')
cursor = mydb.cursor()

with open('./Team_Attributes.csv') as csv_data:
    csv_reader = csv.reader(csv_data)
    next(csv_reader, None)
    for row in csv_reader:
        insert=(
            "INSERT INTO Team_Attributes(id,team_fifa_api_id,team_api_id,date,buildUpPlaySpeed,buildUpPlaySpeedClass,buildUpPlayDribbling,buildUpPlayDribblingClass,buildUpPlayPassing,buildUpPlayPassingClass,buildUpPlayPositioningClass,chanceCreationPassing,chanceCreationPassingClass,chanceCreationCrossing,chanceCreationCrossingClass,chanceCreationShooting,chanceCreationShootingClass,chanceCreationPositioningClass,defencePressure,defencePressureClass,defenceAggression,defenceAggressionClass,defenceTeamWidth,defenceTeamWidthClass,defenceDefenderLineClass)"
            + " VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
        )
        cursor.execute(insert, row[:25])

mydb.commit()
cursor.close()
print("Done")

我使用上面的代码从csv文件中将数据插入到mysql数据库中。 csv文件是来自kaggle.com的足球分析的sqlite数据库的导入结果。但是有一个错误:

  

_mysql_exceptions.OperationalError:(1366,"错误的整数值:''对于列' buildUpPlayDribbling'在第1行和第34行;)

这是csv示例图片: csv image

代码有什么问题?如何解决这个错误?我使用了python 3.5

0 个答案:

没有答案