2017-04-10 42 views
0

我试图从graphlab SFrame访问多行并将它们转换为numpy数组。Graphlab Sframe,检索多行

我有一个96000行和4096列的数据库fd,需要检索存储在numpy数组中的行号。我提出的方法非常缓慢。我怀疑这是因为我在每次迭代中都不断增加sframe的大小,但我不知道是否有预分配值的方法。我需要抓取20000行并且当前的方法没有完成。

fd=fd.add_row_number() 
print(indexes) 
xs=fd[fd['id'] == indexes[0]] #create the first entry 

t=time.time() 
for i in indexes[1:]: #Parse through and get indeces 
    t=time.time() 
    xtemp=fd[fd['id'] == i] 
    xs=xs.append(xtemp) #append the new row to the existing sframe 
    print(time.time()-t) 

xs.remove_column('id') #remove the ID Column 
print(time.time()-t) 
x_sub=xs.to_numpy() #Convert the sframe to numpy 

回答

0

您可以将SFramepandas.DataFrame,发现行与IDS从indexes转换,删除数据帧的专栏'id'这个数据帧转换为numpy.ndarray

例如:

import numpy as np 

fd=fd.add_row_number() 
df = fd.to_dataframe() 
df_indexes = df[df.id.isin(indexes)] 
df_indexes = df_indexes.drop(labels='id', axis=1) 
x_sub = np.array(df_indexes)