Points.sort¶
- Points.sort(by=None, reverse=False, *, useLog=None)¶
Arrange the points in this object.
This sort is stable, meaning the initial point order is retained for points that evaluate as equal.
- Parameters:
by (identifier(s), function, None) –
Based on the parameter type:
identifier(s) - a single feature index or name or a list of feature indices and/or names. For lists, sorting occurs according to the first index with ties being broken in the order of the subsequent indices. Sort follows the natural ordering of the values in the identifier(s).
function - a scorer or comparator function. Must take either one or two positional arguments accepting point views.
None - sort by the point names.
reverse (bool) – Sort as if each comparison were reversed.
useLog (bool, None) – Local control for whether to send object creation to the logger. If None (default), use the value as specified in the “logger” “enabledByDefault” configuration option. If True, send to the logger regardless of the global option. If False, do NOT send to the logger, regardless of the global option.
See also
Examples
Sort by features.
>>> lst = [['home', 81, 3, 2.49], ... ['gard', 98, 10, 0.99], ... ['home', 14, 1, 8.99], ... ['home', 11, 3, 3.89]] >>> fts = ['dept', 'ID', 'quantity', 'price'] >>> orders = nimble.data(lst, featureNames=fts) >>> orders.points.sort(['quantity', 'dept']) >>> orders <DataFrame 4pt x 4ft dept ID quantity price ┌────────────────────────── 0 │ home 14 1 8.990 1 │ home 81 3 2.490 2 │ home 11 3 3.890 3 │ gard 98 10 0.990 >
Sort using a comparator function.
>>> lst = [['home', 81, 3, 2.49], ... ['gard', 98, 10, 0.99], ... ['home', 14, 1, 8.99], ... ['home', 11, 3, 3.89]] >>> fts = ['dept', 'ID', 'quantity', 'price'] >>> orders = nimble.data(lst, featureNames=fts) >>> def incomeDifference(pt1, pt2): ... pt1Income = pt1['quantity'] * pt1['price'] ... pt2Income = pt2['quantity'] * pt2['price'] ... return pt2Income - pt1Income >>> orders.points.sort(incomeDifference) >>> orders <DataFrame 4pt x 4ft dept ID quantity price ┌────────────────────────── 0 │ home 11 3 3.890 1 │ gard 98 10 0.990 2 │ home 14 1 8.990 3 │ home 81 3 2.490 >
Sort using a scoring function.
>>> lst = [['home', 81, 3, 2.49], ... ['gard', 98, 10, 0.99], ... ['home', 14, 1, 8.99], ... ['home', 11, 3, 3.89]] >>> fts = ['dept', 'ID', 'quantity', 'price'] >>> orders = nimble.data(lst, featureNames=fts) >>> def weightedQuantity(pt): ... weights = {'home': 2, 'gard': 0.5} ... score = pt['quantity'] * weights[pt['dept']] ... return score >>> orders.points.sort(weightedQuantity, reverse=True) >>> orders <DataFrame 4pt x 4ft dept ID quantity price ┌────────────────────────── 0 │ home 81 3 2.490 1 │ home 11 3 3.890 2 │ gard 98 10 0.990 3 │ home 14 1 8.990 >
Keywords: arrange, order