cudf.DataFrame.loc#

property DataFrame.loc[source]#

Select rows and columns by label or boolean mask.

Examples

Series

>>> import cudf
>>> series = cudf.Series([10, 11, 12], index=['a', 'b', 'c'])
>>> series
a    10
b    11
c    12
dtype: int64
>>> series.loc['b']
11

DataFrame

DataFrame with string index.

>>> df
   a  b
a  0  5
b  1  6
c  2  7
d  3  8
e  4  9

Select a single row by label.

>>> df.loc['a']
a    0
b    5
Name: a, dtype: int64

Select multiple rows and a single column.

>>> df.loc[['a', 'c', 'e'], 'b']
a    5
c    7
e    9
Name: b, dtype: int64

Selection by boolean mask.

>>> df.loc[df.a > 2]
   a  b
d  3  8
e  4  9

Setting values using loc.

>>> df.loc[['a', 'c', 'e'], 'a'] = 0
>>> df
   a  b
a  0  5
b  1  6
c  0  7
d  3  8
e  0  9