开发者

How do I insert table from numpy into Mysql

I cant get the insert to work in this code. I have other numpy to mysql 开发者_如何学JAVAthat work fine. But there are no errors in running code. Mysql gives no errors. Using python 2.7 and pyodbc on winx64.

p = np.arange(1, 33, 3)
print p

def prow (f1,series):
    rowp=[]
    series = series.tolist()
    ss = series[8:]
    rowp.append(1)       
    rowp.extend(ss)         

    print len (rowp)
    print rowp
    print type(rowp)  

    InSQL  = 'INSERT INTO test._t VALUES (1, 25, 28, 31)' 
    print InSQL
    # csr.executemany(InSQL,rowp)
    csr.execute(InSQL)
    print 1234   
    cxn.commit

prow('foo', p)

MySql is below:

CREATE TABLE `_t` (
  `Id` int(11) DEFAULT NULL,
  `T1` float(12,4) DEFAULT NULL,
  `T2` decimal(12,4) DEFAULT NULL,
  `T7` float(12,4) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1

This print statements give;

[ 1  4  7 10 13 16 19 22 25 28 31]
4
[1, 25, 28, 31]
<type 'list'>
INSERT INTO test._t VALUES (1, 25, 28, 31)
1234

Using the "INSERT INTO test._t VALUES (1, 25, 28, 31)" in mysql shell works just fine. there is alot of redundant code, right now. The idea is to use executemany, but I cant the the simple code to work.


Your commit is missing parens:

cxn.commit

# Should be:
cxn.commit()

Run from the interpreter, cxn.commit without parens simply returns a reference to the commit() method:

# Something like
>>> conn.commit
<built-in method commit of Connection object at 0x9cfe13c>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜