python - Appending bcolz columns with Blaze -
let's first construct ctable:
import pandas pd import blaze bl df = pd.dataframe({'x': range(4), 'y': [2., 4., 2., 4.]}) bl.odo(df, 'test.bcolz') now suppose wanna add column called 'x_mod' table. tried
test_table = bl.data('test.bcolz') def f(h): return h*3 test_table['x_mod'] = test_table['x'].apply(f, dshape='int64') #or, think equivalently: #test_table['x_mod'] = test_table['x']*3 but gives
typeerror: 'interactivesymbol' object not support item assignment 1) how assign 'x_mod' column , save disk? i'm working large databases: calculating column in memory should fine, there's no way can load entire ctable in memory.
2) on related matter, apply doesn't work me either. doing wrong?
#this doesn't work: bl.compute(test_table['x'].apply(f, dshape='int64')) #this think should equivalent, work: bl.compute(test_table['x']*3) thanks time!
you can use transform method in blaze this:
bz.transform(df, sepal_ratio = df.sepal_length / df.sepal_width ) for other function, need use blaze expression:
bz.transform(df, sepal_ratio = blaze_symbolic_expression(df.col1, df.col2) ) it add compute column dataframe. doc here: https://blaze.readthedocs.io/en/latest/expressions.html
for example, can use map:
from datetime import datetime yourexpr = df.col1.map(datetime.utcfromtimestamp) bz.transform(df, sepal_ratio=yourexpr)
Comments
Post a Comment