Series.loc
Access a group of rows by label(s) or a boolean array.
danfo.Series.loc()
Parameters | Type | Description | Default |
---|---|---|---|
rows | Array, String | Array, string slice, index of row positions boolean mask to filter by. |
Examples
.loc()
is label position based (from 0
to length-1
of the row axis).
Allowed inputs are:
An integer, e.g.
"r1"
.A list or array of integers, e.g.
["a", "b", "d"]
.A boolean mask. E.g [ true, false, false ]
A string slice object with ints, e.g.
[
'"a":"d"'], ["1:4"]
Note: only **** the start label is included, and the end label is ignored.
.loc
will raise a ValueEror
if a requested label is not found.
Indexing by specific row index
Index by a slice of row
The loc function also accepts string slices of the form [start: end], e.g [`"a":"e"`]. This will return all values from label positions a
to e
.
Note that when using loc. We expect you to pass labels in the correct format. That is, string labels must be explicitly quoted. For example, the following loc slice will throw an error:
s.loc(["a:e"]).print()
For the slice above to work, you must quote each slice, e.g:
s.loc(["a":"e"]).print()
Inner quotes are not needed for numeric indices!
By specifying a start index in a slice, all values after that index are returned.
Slice Series by boolean condition
Last updated