Fastest way to load numeric data into python/pandas/numpy array from MySQL

前端 未结 2 1531
囚心锁ツ
囚心锁ツ 2021-01-31 22:22

I want to read some numeric (double, i.e. float64) data from a MySQL table. The size of the data is ~200k rows.

MATLAB reference:

tic;
feature accel off;         


        
2条回答
  •  星月不相逢
    2021-01-31 22:54

    Also check out this way of doing things using the turbodbc package. To transform your result set into an OrderedDict of NumPy arrays, just do this:

    import turbodbc
    connection = turbodbc.connect(dsn="My data source name")
    cursor = connection.cursor()
    cursor.execute("SELECT 42")
    results = cursor.fetchallnumpy()
    

    Transforming these results to a dataset should require a few additional milliseconds. I don't know the speedup for MySQL, but I have seen factor 10 for other databases.

    The speedup is mainly achieved by using bulk operations instead of row-wise operations.

提交回复
热议问题