2017-04-10 9 views
0

グラフラブ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

あなたは、データフレームの列'id'を削除し、numpy.ndarrayに、このデータフレームを変換し、indexesからIDを持つ行を見つけ、あなたのSFramepandas.DataFrameに変換することができます。例えば

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) 
関連する問題