dask dataframe head()返回空df [英] dask dataframe head() returns empty df

查看:98
本文介绍了dask dataframe head()返回空df的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个dask数据框,其中一列具有索引。
问题是,如果我执行df.head(),它总是会变空一个df,而df.tail总是会返回正确的df。我检查df.head的
始终检查第一个分区中的前n个条目。因此,如果我执行df.reset_index(),它应该可以工作,但事实并非如此

I have a dask dataframe with an index on one of the columns. The issue is if I do a df.head() it always treturns an empty df, whereas df.tail always returns the correct df. I checked df.head always checks for the first n entries in the first partition. So if i do df.reset_index(), it should work but thats not the case

下面是重现此代码的代码:

Below is the code to reproduce this:

import dask.dataframe as dd
import pandas as pd

data = pd.DataFrame({
     'i64': np.arange(1000, dtype=np.int64),
     'Ii32': np.arange(1000, dtype=np.int32),
     'bhello': np.random.choice(['hello', 'Yo', 'people'], size=1000).astype("O")
})

daskDf = dd.from_pandas(data, chunksize=3)
daskDf = daskDf.set_index('bhello')
print(daskDf.head())


推荐答案

尝试使用 npartitions = -1 调用 head ,以使用所有分区(默认情况下,仅使用第一个,并且可能没有足够的元素返回 head )。

Try calling head with npartitions=-1, to use all partitions (by default, only the first is used, and there may not be enough elements to return the head).

daskDf.head(npartitions=-1)

这篇关于dask dataframe head()返回空df的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆