Python 如何将序列或序列分配给dask数据帧列?
我的dask数据帧如下所示:Python 如何将序列或序列分配给dask数据帧列?,python,dataframe,dask,Python,Dataframe,Dask,我的dask数据帧如下所示: 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
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
分配整数可以:
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
但是,在现有列中,没有其他方法可以指定系列或任何其他iterable
如何实现这一点?DataFrame.assign接受任何标量或任何
dd.Series
df = df.assign(a=1) # accepts scalars
df = df.assign(z=df.x + df.y) # accepts dd.Series objects
如果您试图分配NumPy数组或Python列表,则可能是您的数据太小,无法放入RAM中,因此Pandas可能比Dask.dataframe更适合
也可以使用普通的setitem语法
df['a'] = 1
df['z'] = df.x + df.y