使用set_index使用dask系列在dask dataframe上使用set_index时长度不匹配错误
import pandas as pd
import numpy as np
import dask.array as dka
import dask.dataframe as dkf
vals = np.arange(200).reshape(20,10)
vals = dka.from_array(vals)
columns = [f"col_{i}" for i in range(10)]
ser = pd.Series(range(20), index=np.arange(20)+100, name='idx')
ddf = dkf.from_dask_array(vals, columns=columns)
dks = dkf.from_pandas(ser, npartitions=ddf.npartitions)
ddf.set_index(dks, sorted=True).compute()
-----------------
ValueError: Length mismatch: Expected 19 rows, received array of length 0
我对这个错误感到困惑,dks
有20个元素,为什么dask
抱怨它的长度为0?当ddf
有20行时,为什么要期望19行?
import pandas as pd
import numpy as np
import dask.array as dka
import dask.dataframe as dkf
vals = np.arange(200).reshape(20,10)
vals = dka.from_array(vals)
columns = [f"col_{i}" for i in range(10)]
ser = pd.Series(range(20), index=np.arange(20)+100, name='idx')
ddf = dkf.from_dask_array(vals, columns=columns)
dks = dkf.from_pandas(ser, npartitions=ddf.npartitions)
ddf.set_index(dks, sorted=True).compute()
-----------------
ValueError: Length mismatch: Expected 19 rows, received array of length 0
I'm confused about this error, dks
has 20 elements, why does dask
complain it has length 0? and why does it expect 19 rows when the ddf
has 20 rows?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论