2

最初に を構築しましょうctable:

import pandas as pd
import blaze as bl

df = pd.DataFrame({'x': range(4), 'y': [2., 4., 2., 4.]})
bl.odo(df, 'test.bcolz')

ここで、このテーブルに「x_mod」という列を追加したいとします。私は試した

test_table = bl.Data('test.bcolz')

def f(h):
    return h*3
test_table['x_mod'] = test_table['x'].apply(f, dshape='int64')
#Or, I think equivalently:
#test_table['x_mod'] = test_table['x']*3

しかし、それは与えます

TypeError: 'InteractiveSymbol' object does not support item assignment

1) 「x_mod」列を割り当ててからディスクに保存するにはどうすればよいですか? 大規模なデータベースを扱っています。メモリ内の列を計算することは問題ないはずですが、全体ctableをメモリにロードする方法がありません。

2)関連する問題については、apply私にとってもうまくいきません。私は何か間違ったことをしていますか?

#This doesn't work:
bl.compute(test_table['x'].apply(f, dshape='int64'))

#This I think should be equivalent, but does work:
bl.compute(test_table['x']*3)

御時間ありがとうございます!

4

1 に答える 1

2

次のように、Blaze で transform メソッドを使用できます。

bz.transform(df, sepal_ratio = df.sepal_length / df.sepal_width   )

他の関数については、Blaze 式を使用する必要があります。

bz.transform(df, sepal_ratio = BLAZE_symbolic_Expression(df.Col1, df.col2)  )

計算列をデータフレームに追加します。ドキュメントはこちら: https://blaze.readthedocs.io/en/latest/expressions.html

たとえば、マップを使用できます。

from datetime import datetime
yourexpr = df.col1.map(datetime.utcfromtimestamp)
bz.transform(df, sepal_ratio=yourexpr)
于 2016-12-09T12:45:12.797 に答える