2016-09-14 2 views
1

私はパンダを使用できないWebアプリケーションを導入しています。私はaws上でpython3と弾力のあるbeanstalkを使用していますが、さまざまな依存関係は現時点では利用できません。pandasパッケージなしでPythonでデータフレームを作成する最も簡単な方法は?

私は単なる関数でパンダが必要です。使い方はかなり簡単です:いくつかのデータフレームを作り、df.locで検索してください。 - >df.loc[index, col]の機能を持つパンダの良い選択肢は誰にも分かりますか?

+0

/wのインデックスよりも高速です。組み込みのdictオブジェクトを使用して750 Mbのファイルをキャプチャすると、20 GB以上のRAMが必要になります。パンダは4のように読み込みます。 https://www.youtube.com/watch?v=lsJLLEwUYZM – kpie

+0

numpyを使用できますか?それ以外の場合は、[名前付きタプル](https://docs.python.org/3/library/collections.html#collections.namedtuple) – JGreenwell

答えて

0

df_eq = {'col1' : [list, of, column, data], 
     'col2' : [list, of, column, data], 
     ..., 
     'coln-1' : [list, of, column, data], 
     'coln' : [list, of, column, data]} 

次に、あなたがlocのようなものを使用することができます。あなたは、パンダを持っているパンダを取得しない場合はまた、インデックスnumpypandas

Ar_data = np.array([["gyrados","raichu","mu","dragonair","vaporeon"],["water","electric","normal","dragon","water"], [0,0,0,1,2]]).T 
Ar_data 
# array([['gyrados', 'water', '0'], 
#  ['raichu', 'electric', '0'], 
#  ['mu', 'normal', '0'], 
#  ['dragonair', 'dragon', '1'], 
#  ['vaporeon', 'water', '2']], 
#  dtype='<U9') 

# Index w/ ints `.iloc` 
Ar_data[3,1] 
# 'dragon' 

fields = ["pokemon","status","meta"] 
observations = ["p1","p2","p3","p4","p5"] 

# Index w/ labels `.loc` 
Ar_data[3,fields.index("pokemon")] 
# 'dragonair' 

Ar_data[observations.index("p4"),fields.index("pokemon")] 
# 'dragonair' 

# Time it 
DF_data = pd.DataFrame(Ar_data, columns=fields, index=observations) 
%timeit DF_data.iloc[3,1] 
%timeit Ar_data[3,1] 
# 10000 loops, best of 3: 129 µs per loop 
# The slowest run took 21.69 times longer than the fastest. This could mean that an intermediate result is being cached. 
# 1000000 loops, best of 3: 384 ns per loop 
3

あなたは最良のオプションは、辞書にリストを使用することです:私はちょうどnumpyを使用することになり

df_eq['coln'][idx] 
関連する問題