从 DASK 数据帧中按索引选择几行?


df = dd.read_csv('csv',usecols=fields,skip_blank_lines=True)
len(df.iloc[0:5])

上面的代码引发

AttributeError: 'DataFrame' object has no attribute 'iloc'

尝试了 ix loc,但无法根据索引选择行

Dask.dataframe 不支持iloc。 通常,如果不先将其全部读取到内存中,就很难访问 csv 文件中的任何特定行。

但是,如果您只想在顶部显示几行,那么我建议您使用.head()方法

>>> df.head()

一种解决方法是将索引创建为列,即df_index,在您的 csv 文件中并像这样使用它:

selection = (df[ df['df_index'].isin( list_of_indexes ) ]).compute()

最新更新