pandas
하는 numpy
을 기반으로 매우 빠른입니다 C
기반 file parser 있습니다
# generate some integer data (5 M rows, two cols) and write it to file
In [24]: data = np.random.randint(1000, size=(5 * 10**6, 2))
In [25]: np.savetxt('testfile.txt', data, delimiter=' ', fmt='%d')
# your way
In [26]: def your_way(filename):
...: G = []
...: with open(filename, 'r') as f:
...: for line in f:
...: G.append(list(map(int, line.split(','))))
...: return G
...:
In [26]: %timeit your_way('testfile.txt', ' ')
1 loops, best of 3: 16.2 s per loop
In [27]: %timeit pd.read_csv('testfile.txt', delimiter=' ', dtype=int)
1 loops, best of 3: 1.57 s per loop
그래서 pandas.read_csv
약 10 배 빠른 속도로 당신의 방법보다 데이터를 읽고 약 1과 2 분의 1 초를 취하고있다.
출처
2013-02-26 19:46:51
bmu
목록을 이해하십시오. –
'numpy'를 사용하지 않는 이유가 있습니까? – DSM
"거대한"을 정의하십시오. 또한, 각 라인은 동일한 정수를 가지고 있습니까? –