我花了两天的时间来弄清楚我的代码会发生什么。我从数据帧创建了一个数据库文件。问题是,当我选择包含带有整数列的where语句的语句时,我会得到返回的记录,但当我使用字符串列时,我不会得到任何值
con = sqlite3.connect("sqladb.db")
select_str='''select * from sqladb where age=40 limit 2;'''
results=con.execute(select_str)
for rec in results:
print(rec)
上面的代码返回记录
select_str='''select * from sqladb where sex='Male' limit 2;'''
results=con.execute(select_str)
for rec in results:
print(rec)
当有记录时,上述代码不返回任何值。列sex是一个字符串
我希望输出与记录根据我的声明
Copy from Comment:
CREATE TABLE "sqladb" ( "age" INTEGER, "workclass" TEXT, "fnlwgt" INTEGER, "education" TEXT, "education-num" INTEGER, "marital-status" TEXT, "occupation" TEXT, "relationship" TEXT, "race" TEXT, "sex" TEXT, "capital-gain" INTEGER, "capital-loss" INTEGER, "hours-per-week" INTEGER, "native-country" TEXT, "label" TEXT )
(39, ' State-gov', 77516, ' Bachelors', 13, ' Never-married', ' Adm-clerical', ' Not-in-family', ' White', ' Male', 2174, 0, 40, ' United-States', ' <=50K')
(50, ' Self-emp-not-inc', 83311, ' Bachelors', 13, ' Married-civ-spouse', ' Exec-managerial', ' Husband', ' White', ' Male', 0, 0, 13, ' United-States', ' <=50K')
(38, ' Private', 215646, ' HS-grad', 9, ' Divorced', ' Handlers-cleaners', ' Not-in-family', ' White', ' Male', 0, 0, 40, ' United-States', ' <=50K')
目前没有回答
相关问题 更多 >
编程相关推荐