You are viewing documentation about an older version (1.22.1). View latest version

modin.pandas.DataFrame.iloc¶

property DataFrame.iloc[source]¶

Purely integer-location based indexing for selection by position.

.iloc[] is primarily integer position based (from 0 to length-1 of the axis), but may also be used with a boolean array.

Allowed inputs are:

  • An integer, e.g. 5, -1.

  • A list or array of integers, e.g. [4, 3, 0].

  • A slice object with ints, e.g. 1:7.

  • A boolean array.

  • A callable function with one argument (the calling Series or DataFrame) and that returns valid output for indexing (one of the above). This is useful in method chains, when you don’t have a reference to the calling object, but would like to base your selection on some value.

  • A tuple of row and column indexes. The tuple elements consist of one of the above inputs, e.g. (0, 1).

Notes

To meet the nature of lazy evaluation:

  • Snowpark pandas .iloc ignores out-of-bounds indexing for all types of indexers (while pandas .iloc will raise error except slice indexer). If all values are out-of-bound, an empty result will be returned.

  • In Snowpark pandas .iloc, the length of boolean list-like indexers (e.g., list, Series, Index, numpy ndarray) does not need to be the same length as the row/column being indexed. Internally a join is going to be performed so missing or out of bound values will be ignored.

See also

DataFrame.iat

Fast integer location scalar accessor.

DataFrame.loc

Purely label-location based indexer for selection by label.

Series.iloc

Purely integer-location based indexing for selection by position.

Examples

>>> mydict = [{'a': 1, 'b': 2, 'c': 3, 'd': 4},
...           {'a': 100, 'b': 200, 'c': 300, 'd': 400},
...           {'a': 1000, 'b': 2000, 'c': 3000, 'd': 4000}]
>>> df = pd.DataFrame(mydict)
>>> df
      a     b     c     d
0     1     2     3     4
1   100   200   300   400
2  1000  2000  3000  4000
Copy

Indexing just the rows

With a scalar integer.

>>> type(df.iloc[0])
<class 'modin.pandas.series.Series'>
>>> df.iloc[0]
a    1
b    2
c    3
d    4
Name: 0, dtype: int64
Copy
>>> df.iloc[-1]
a    1000
b    2000
c    3000
d    4000
Name: 2, dtype: int64
Copy

With a list of integers.

>>> df.iloc[[0]]
   a  b  c  d
0  1  2  3  4
Copy
>>> df.iloc[[0, 1]]
     a    b    c    d
0    1    2    3    4
1  100  200  300  400
Copy

With out-of-bound values in the list and those out of bound values will be ignored.

>>> df.iloc[[0, 1, 10, 11]]
     a    b    c    d
0    1    2    3    4
1  100  200  300  400
Copy

With all out-of-bound values. Return empty dataset.

>>> df.iloc[[10, 11, 12]]
Empty DataFrame
Columns: [a, b, c, d]
Index: []
Copy

With a slice object.

>>> df.iloc[:3]
      a     b     c     d
0     1     2     3     4
1   100   200   300   400
2  1000  2000  3000  4000
Copy

With a boolean mask the same length as the index.

>>> df.iloc[[True, False, True]]
      a     b     c     d
0     1     2     3     4
2  1000  2000  3000  4000
Copy

When a boolean mask shorter than the index.

>>> df.iloc[[True, False]]      
      a     b     c     d
0     1     2     3     4
Copy

When a boolean mask longer than the index.

>>> df.iloc[[True, False, True, True, True]]      
      a     b     c     d
0     1     2     3     4
2  1000  2000  3000  4000
Copy

With a callable, useful in method chains. The x passed to the lambda is the DataFrame being sliced. This selects the rows whose index labels are even.

>>> df.iloc[lambda x: x.index % 2 == 0]
      a     b     c     d
0     1     2     3     4
2  1000  2000  3000  4000
Copy

Indexing both axes

You can mix the indexer types for the index and columns. Use : to select the entire axis.

With scalar integers.

>>> df.iloc[0, 1]
2
Copy

With lists of integers.

>>> df.iloc[[0, 2], [1, 3]]
      b     d
0     2     4
2  2000  4000
Copy

With slice objects.

>>> df.iloc[1:3, 0:3]
      a     b     c
1   100   200   300
2  1000  2000  3000
Copy

With a boolean array whose length matches the columns.

>>> df.iloc[:, [True, False, True, False]]
      a     c
0     1     3
1   100   300
2  1000  3000
Copy

With a callable function that expects the Series or DataFrame.

>>> df.iloc[:, lambda df: [0, 2]]
      a     c
0     1     3
1   100   300
2  1000  3000
Copy