python - How do I assign series or sequences to dask dataframe column? -
my dask dataframe follwing:
in [65]: df.head() out[65]: id_orig id_cliente id_cartao inicio_processo fim_processo score \ 0 1.0 1.0 1.0 1.0 1.0 1.0 1 1.0 1.0 1.0 1.0 1.0 1.0 2 1.0 1.0 1.0 1.0 1.0 1.0 3 1.0 1.0 1.0 1.0 1.0 1.0 4 1.0 1.0 1.0 1.0 1.0 1.0 automatico canal aceito motivo_recusa variante 0 1.0 1.0 1.0 1.0 1.0 1 1.0 1.0 1.0 1.0 1.0 2 1.0 1.0 1.0 1.0 1.0 3 1.0 1.0 1.0 1.0 1.0 4 1.0 1.0 1.0 1.0 1.0
assigning integer works:
in [92]: df = df.assign(id_cliente=999) in [93]: df.head() out[93]: id_orig id_cliente id_cartao inicio_processo fim_processo score \ 0 1.0 999 1.0 1.0 1.0 1.0 1 1.0 999 1.0 1.0 1.0 1.0 2 1.0 999 1.0 1.0 1.0 1.0 3 1.0 999 1.0 1.0 1.0 1.0 4 1.0 999 1.0 1.0 1.0 1.0 automatico canal aceito motivo_recusa variante 0 1.0 1.0 1.0 1.0 1.0 1 1.0 1.0 1.0 1.0 1.0 2 1.0 1.0 1.0 1.0 1.0 3 1.0 1.0 1.0 1.0 1.0 4 1.0 1.0 1.0 1.0 1.0
however no other method assigning series or other iterable in existing columns works.
how can achieve that?
dataframe.assign accepts scalar or dd.series
df = df.assign(a=1) # accepts scalars df = df.assign(z=df.x + df.y) # accepts dd.series objects
if trying assign numpy array or python list might data small enough fit in ram, , pandas might better fit dask.dataframe.
you can use plain setitem syntax
df['a'] = 1 df['z'] = df.x + df.y
Comments
Post a Comment