import records

db = records.Database('sqlite:///{}'.format("predict.db"))

print()
out= db.query('SELECT COUNT(stock_name) from STOCK WHERE sp500_2018 = "true" and nasdaq_2018 = "true"')
for item in out:
print(item["COUNT(stock_name)"])

改成

import records

db = records.Database('sqlite:///{}'.format("predict.db"))

db = db.get_connection() # 新加

print()
out= db.query('SELECT COUNT(stock_name) from STOCK WHERE sp500_2018 = "true" and nasdaq_2018 = "true"')
for item in out:
print(item["COUNT(stock_name)"])