Python : odbc data load error -


i use pyodbc import sql big data. there no error,no saved file , no message.(data has 300000 rows , 600 columns)

how load big data in python odbc?

this code:

import pyodbc import pandas pd  h2=pyodbc.connect('driver={sql server}; server={192.168.x.x};database={h2};uid=hoho;pwd=haha') cursor=h2.cursor() cursor.execute("select  * [dbo].[hist_utdata001_201506]") fieldnames1=[f[0] f in cursor.description] result=[] result=cursor.fetchmany(1000) b1=result while b1:        b1=cursor.fetchmany(1000)       if not b1:             break       result.extend(b1)   df = pd.dataframe(result,columns=[fieldnames1]) df.to_csv('test1.csv') 

you running out of memory. column integer (8 bytes) require (approx.) 16 additional bytes python objects , pointers them. makes 24 bytes per column. adding numbers, require @ least 24 * 600 * 300,000 = 4,320,000,000 bytes. need more strings.

you try turbodbc. faster pyodbc , offers built-in numpy support avoid python objects numbers. may reduce memory consumption.


Comments