私はこの仕事のためにパンダを試してみます。それは非常に簡単で、あなたに多くの力を与えます。 (iPythonから、それは約取った私の自宅のノートPC上で2分。)
import time
import numpy as np
import pandas as pd
# let's generate some sample data (8000 rows, 800 columns)
data = np.random.randint(0, 100, (8000, 800))
# let's generate column names from 'col001' to 'col800'
cols = ['col{0:02d}'.format(i) for i in range(1,801)]
# generating Pandas data frame from numpy array
df = pd.DataFrame(data, columns=cols)
# write generated DF (Data Frame) to Excel file
df.to_excel(r'd:/temp/sample.xlsx', index=False)
# we are done with sample data
#####################################################################
#
# interesting part starts here ...
#
#####################################################################
start = time.time()
# read up the Excel file (skipping first two rows)
df = pd.read_excel(r'd:/temp/sample.xlsx', skiprows=2)
print "Done", time.time()-start
# print the shape of out DF
print(df.shape)
出力:ここ
は小さな一例である今、あなたは、メモリ内のすべてのデータなどを持っている
In [24]: %paste
start = time.time()
# read up the Excel file
df = pd.read_excel(r'd:/temp/sample.xlsx', skiprows=2)
print "Done", time.time()-start
## -- End pasted text --
Done 124.375999928
In [25]:
In [25]: df.shape
Out[25]: (7998, 800)
In [26]: # print the shape of out DF
In [27]: print(df.shape)
(7998, 800)
DFを使用して、すべてのパンダのパワーを使って非常に快適に処理できます
PS次のPythonモジュールをインストールする必要があります:
Excelファイルは、長方形のシートであることを考えると、私は巨大なスピードを得るように私が取る場合は3210匹の
- numpyの
- パンダ
- はopenpyxlまたはXlsxWriter(あるいはその両方)
にしています - それは非常に簡単で、非常に素敵で高速なアルゴリズムの中で使用します。 – MaxU
7 * 60 /(8000 * 800)〜= 0,066 miliseconds/cellこれはあまりにも悪くないようです。 –
イテレータなしでコードを実行しようとしましたか?つまり、 'use_iterators = False'ですか? –