What's the most efficient way to convert a MySQL result set to a NumPy array?

前端 未结 3 1766
暖寄归人
暖寄归人 2020-12-01 13:00

I\'m using MySQLdb and Python. I have some basic queries such as this:

c=db.cursor()
c.execute(\"SELECT id, rating from video\")
results = c.fetchall()
         


        
3条回答
  •  盖世英雄少女心
    2020-12-01 13:27

    The fetchall method actually returns an iterator, and numpy has the fromiter method to initialize an array from an interator. So, depending on what data is in the table you could combine the two easily, or use an adapter generator.

提交回复
热议问题