Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

selecting few rows by index from dask dataframe?

Tags:

dask

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

The above code raises

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

tried ix loc but unable select rows based on index

like image 256
madnavs Avatar asked Mar 07 '23 07:03

madnavs


2 Answers

Dask.dataframe does not support iloc. Generally it's quite hard to do access any particular row in a csv file without first reading it all into memory.

However if you only want a few of the rows at the top then I recommend using the .head() method

>>> df.head()
like image 56
MRocklin Avatar answered May 18 '23 12:05

MRocklin


One workaround is to create the index as a column, i.e. df_index, in your csv file and use it like so:

selection = (df[ df['df_index'].isin( list_of_indexes ) ]).compute()
like image 37
scottlittle Avatar answered May 18 '23 13:05

scottlittle