重塑dask数组(从dask dataframe列获得) [英] Reshape a dask array (obtained from a dask dataframe column)
本文介绍了重塑dask数组(从dask dataframe列获得)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对dask并不陌生,正在尝试弄清楚如何重整我从dask数据帧的单个列中获得的dask数组,并且遇到了错误。想知道是否有人可能知道此修复程序(而不必强制执行计算)?谢谢!
I am new to dask and am trying to figure out how to reshape a dask array that I've obtained from a single column of a dask dataframe and am running into errors. Wondering if anyone might know of the fix (without having to force a compute)? Thanks!
示例:
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])
推荐答案
也:
ddf['x'].to_dask_array(lengths=True).reshape([-1,1])
这篇关于重塑dask数组(从dask dataframe列获得)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文