连接到Python时尝试在MySQL上删除专栏

时间:2020-04-21 14:42:30

标签: python mysql mysql-connector-python

我在Python上使用机器学习决策树连接到MySQL上的数据库,并且在代码中使用数据库中的值时遇到错误。 python上的代码接收与存储在MySQL中的UPC值匹配的输入,并输出与要在python中使用的匹配的行。在比较决策树功能之一中的值时出现错误,并且认为这是导致此错误的UPC值,因为它是长整数。有没有办法使行中的其他元素匹配而不带UPC值呢?我收到的错误消息可能不是由于这个原因,但是当将值导入决策树时,我也不想使用UPC列。

CARMLScursor = mydb.cursor()

print("Enter upc codes via scanner (type f to finish list): ")

try:
    input_upc = []

    while True:
        input_upc.append(int(input()))

except:
    print("Listed UPC input:", input_upc)

CARMLScursor.execute("use supermarket")

sqlFormula = "INSERT INTO user_input (Barcode) VALUES(%s)"

records = zip(input_upc)

CARMLScursor.executemany(sqlFormula, records)

mydb.commit()

SQL connection:
copy = "SELECT t1.* FROM items t1, user_input t2 WHERE (t1.UPC=t2.Barcode) " \
       "GROUP BY t1.UPC, t1.Shelf, t1.Isle, t1.ItemName ORDER BY Isle ASC"

CARMLScursor.execute(copy)

result = [CARMLScursor.fetchall()]

for training_data in result:

    print(training_data)

零件接收错误:

class Question:

    def __init__(self, column, value):
        self.column = column
        self.value = value

    def match(self, example):
        # Compare the feature value in an example to the
        # feature value in this question.
        val = example[self.column + 2]
        if is_numeric(val):
            return val >= self.value
        else:
            return val == self.value

    def __repr__(self):
        # This is just a helper method to print
        # the question in a readable format.
        condition = "=="
        if is_numeric(self.value):
            condition = ">="
        return "Is %s %s %s?" % (
            header[self.column], condition, str(self.value))

q = Question(0, 'Cereal')
print(q)

example = training_data[0]
print(q.match(example))


def partition(rows, question):

    true_rows, false_rows = [], []
    for row in rows:
        if question.match(row):
            true_rows.append(row)
        else:
            false_rows.append(row)
    return true_rows, false_rows

第116行,在比赛中返回val> = self.value TypeError:'int'和'str'的实例之间不支持'> ='

这显示了用作清单的表,其中已扫描的UPC与存储的UPC相匹配。还有一个名为user_input的表,其中存储了与项目表具有相同属性的扫描的UPC值。

|-------------------|--------------|------------|---------------|                  
|        UPC        |     Shelf    |    Isle    |    ItemName   |                  
|-------------------|--------------|------------|---------------|                  
|    123456789851   |       C      |     1      |     Eggs      |                 
|-------------------|--------------|------------|---------------|                  
|    123456789789   |       A      |     1      |     Milk      |                 
|-------------------|--------------|------------|---------------|                  
|    123456789765   |       D      |     2      |     Coffee    |                 
|-------------------|--------------|------------|---------------|                  
|    123456789582   |       A      |     5      | Apple Juice   |                 
|-------------------|--------------|------------|---------------|                 
|    123456789542   |       S      |     2      |     Cereal    |                 
|-------------------|--------------|------------|---------------|                    

0 个答案:

没有答案