cudf.DataFrame.iloc#

property DataFrame.iloc[source]#

Select values by position.

Examples

Series

>>> import cudf
>>> s = cudf.Series([10, 20, 30])
>>> s
0    10
1    20
2    30
dtype: int64
>>> s.iloc[2]
30

DataFrame

Selecting rows and column by position.

>>> df = cudf.DataFrame({'a': range(20),
...                      'b': range(20),
...                      'c': range(20)})

Select a single row using an integer index.

>>> df.iloc[1]
a    1
b    1
c    1
Name: 1, dtype: int64

Select multiple rows using a list of integers.

>>> df.iloc[[0, 2, 9, 18]]
      a    b    c
 0    0    0    0
 2    2    2    2
 9    9    9    9
18   18   18   18

Select rows using a slice.

>>> df.iloc[3:10:2]
     a    b    c
3    3    3    3
5    5    5    5
7    7    7    7
9    9    9    9

Select both rows and columns.

>>> df.iloc[[1, 3, 5, 7], 2]
1    1
3    3
5    5
7    7
Name: c, dtype: int64

Setting values in a column using iloc.

>>> df.iloc[:4] = 0
>>> df
   a  b  c
0  0  0  0
1  0  0  0
2  0  0  0
3  0  0  0
4  4  4  4
5  5  5  5
6  6  6  6
7  7  7  7
8  8  8  8
9  9  9  9
[10 more rows]