DataFrame.loc
Access a group of rows and columns by label(s)
danfo.DataFrame.loc(args)
args
Object
{
rows: Array, labels, Boolean mask of row index
columns: Array, labels of column names
}
Examples
.loc() is label position based-from 0 to length-1 of the row axis.
Allowed inputs for 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.
Index by specific rows and return all columns
If the row's index is specified and the columns are not, then it returns all columns and just the specified rows.
const dfd = require("danfojs-node")
let data = { "Name": ["Apples", "Mango", "Banana", "Pear"],
"Count": [21, 5, 30, 10],
"Price": [200, 300, 40, 250] }
let df = new dfd.DataFrame(data, {index: ["a", "b", "c", "d"]})
df.print()
let sub_df = df.loc({rows: ["a", "c"]})
sub_df.print()Index by a list of column names and return all rows
Index both axes by the specified labels
Index by a slice of row
The loc function also accepts string slices of the form [start: end], e.g [`"a":"c"`]. This will return all values from label positions a to c.
Slice DataFrame rows by boolean condition
Slice DataFrame rows by multiple boolean conditions
Slice DataFrame with boolean mask
Last updated
Was this helpful?