我是 dask 新手,正在尝试弄清楚如何重塑从 dask 数据帧的单列获得的 dask 数组,但遇到了错误。想知道是否有人知道修复方法(无需强制计算)?谢谢!
Example:
import pandas as pd
import numpy as np
from dask import dataframe as dd, array as da
df = pd.DataFrame({'x': [1, 2, 3], 'y': [4, 5, 6]})
ddf = dd.from_pandas(df, npartitions=2)
# This does not work - error ValueError: cannot convert float NaN to integer
ddf['x'].values.reshape([-1,1])
# this works, but requires a compute
ddf['x'].values.compute().reshape([-1,1])
# this works, if the dask array is created directly from a np array
ar = np.array([1, 2, 3])
dar = da.from_array(ar, chunks=2)
dar.reshape([-1,1])
Also:
ddf['x'].to_dask_array(lengths=True).reshape([-1,1])
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)