快速修复方法是添加数据帧的副本:
def func2(df):
df = df.copy() # will make a copy of the dataframe
df['id2'] = df['balance2'] + 1
return df
然而,据我所知,不需要复制数据帧,因为dask数据帧的延迟特性意味着更改不会传播回dask数据框架分区。
更新:存在
relevant question
这就解释了
.copy
在里面
pandas
。在下面的代码段中,应用该函数将修改原始pandas数据帧,这可能是不可取的:
from pandas import DataFrame
def addcol(df):
df['a'] = 1
return df
df = DataFrame()
df1 = addcol(df)
# without .copy, df is also modified, which might be undesirable
在
dask
这个警告只是一个警告,所以
复制
不需要。
from dask.dataframe import from_pandas
ddf = from_pandas(df, npartitions=1)
ddf1 = ddf.map_partitions(addcol)
# will show warning, but original ddf is not modified