除了阈值是延迟数字,是否有办法做到这一点?
import dask
import pandas as pd
import dask.dataframe as dd
threshold = 3
df = pd.DataFrame({'something': [1,2,3,4]})
ddf = dd.from_pandas(df, npartitions=2)
ddf[ddf['something'] >= threshold]
如果threshold
是:
threshold = dask.delayed(3)
自动取款机给我:
TypeError('Truth of Delayed objects is not supported')
我想将ddf
保留为淡淡的数据框,而不要将其转换为熊猫数据框。想知道是否存在也采用延迟值的组合器形式。
答案 0 :(得分:2)
Dask无法知道该Delayed对象中的具体值是整数,因此无法知道在操作中(对齐,广播等)如何处理它
如果使用大小为0的数组,则看起来一切正常
In [32]: df = dd.from_pandas(pd.DataFrame({"A": [1, 2, 3, 4]}), 2)
In [33]: threshold = da.from_array(np.array([3]))[0]
In [34]: df.A > threshold
Out[34]:
Dask Series Structure:
npartitions=2
0 bool
2 ...
3 ...
Name: A, dtype: bool
Dask Name: gt, 8 tasks
In [35]: df[df.A > threshold].compute()
Out[35]:
A
3 4