请教一下,我应该如何解决这个问题?
5 个解决方案
#1
我是使用pymysql模块:
sql = "INSERT INTO data_index_detail(date,indexcode,indexname,changepct,open,preclose,close,high,low,volume,amount) VALUES (CURDATE(),%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
sql = "INSERT INTO data_index_detail(date,indexcode,indexname,changepct,open,preclose,close,high,low,volume,amount) VALUES (CURDATE(),%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
#2
字符型要加引号吧
print sql 看看最后生成的语句是啥、
print sql 看看最后生成的语句是啥、
#3
把numpy的float等转成字符串。
#4
请问语法要怎么写啊?我是刚学python的小白。
#5
我的代码如下:
import pymysql.cursors
import tushare as ts
import numpy as np
config = {
"host":"localhost",
"port":3306,
"user":"root",
"password":"******",
"db":"stock_pnsl",
"charset":"utf8mb4",
"cursorclass":pymysql.cursors.DictCursor,
}
connection = pymysql.connect(**config)
index = ts.get_index()
try:
with connection.cursor() as cursor:
for i in range(len(index)):
line = tuple(index.iloc[i])
sql = "INSERT INTO data_index(code,name,changepct,open,preclose,close,high,low,volume,amount) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
cursor.execute(sql,line);
connection.commit()
finally:
connection.close();
import pymysql.cursors
import tushare as ts
import numpy as np
config = {
"host":"localhost",
"port":3306,
"user":"root",
"password":"******",
"db":"stock_pnsl",
"charset":"utf8mb4",
"cursorclass":pymysql.cursors.DictCursor,
}
connection = pymysql.connect(**config)
index = ts.get_index()
try:
with connection.cursor() as cursor:
for i in range(len(index)):
line = tuple(index.iloc[i])
sql = "INSERT INTO data_index(code,name,changepct,open,preclose,close,high,low,volume,amount) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
cursor.execute(sql,line);
connection.commit()
finally:
connection.close();
#1
我是使用pymysql模块:
sql = "INSERT INTO data_index_detail(date,indexcode,indexname,changepct,open,preclose,close,high,low,volume,amount) VALUES (CURDATE(),%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
sql = "INSERT INTO data_index_detail(date,indexcode,indexname,changepct,open,preclose,close,high,low,volume,amount) VALUES (CURDATE(),%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
#2
字符型要加引号吧
print sql 看看最后生成的语句是啥、
print sql 看看最后生成的语句是啥、
#3
把numpy的float等转成字符串。
#4
请问语法要怎么写啊?我是刚学python的小白。
#5
我的代码如下:
import pymysql.cursors
import tushare as ts
import numpy as np
config = {
"host":"localhost",
"port":3306,
"user":"root",
"password":"******",
"db":"stock_pnsl",
"charset":"utf8mb4",
"cursorclass":pymysql.cursors.DictCursor,
}
connection = pymysql.connect(**config)
index = ts.get_index()
try:
with connection.cursor() as cursor:
for i in range(len(index)):
line = tuple(index.iloc[i])
sql = "INSERT INTO data_index(code,name,changepct,open,preclose,close,high,low,volume,amount) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
cursor.execute(sql,line);
connection.commit()
finally:
connection.close();
import pymysql.cursors
import tushare as ts
import numpy as np
config = {
"host":"localhost",
"port":3306,
"user":"root",
"password":"******",
"db":"stock_pnsl",
"charset":"utf8mb4",
"cursorclass":pymysql.cursors.DictCursor,
}
connection = pymysql.connect(**config)
index = ts.get_index()
try:
with connection.cursor() as cursor:
for i in range(len(index)):
line = tuple(index.iloc[i])
sql = "INSERT INTO data_index(code,name,changepct,open,preclose,close,high,low,volume,amount) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
cursor.execute(sql,line);
connection.commit()
finally:
connection.close();