MCPcopy Index your code
hub / github.com/javascriptdata/danfojs / sortValues

Method sortValues

src/danfojs-base/core/frame.ts:2350–2387  ·  view source on GitHub ↗
(
        column: string,
        options?:
            {
                ascending?: boolean
                inplace?: boolean
            }
    )

Source from the content-addressed store, hash-verified

2348 }
2349 ): DataFrame
2350 sortValues(
2351 column: string,
2352 options?:
2353 {
2354 ascending?: boolean
2355 inplace?: boolean
2356 }
2357 ): DataFrame | void {
2358 const { ascending, inplace } = { ascending: true, inplace: false, ...options }
2359
2360 if (!column) {
2361 throw Error(`ParamError: must specify a column to sort by`);
2362 }
2363
2364 if (this.columns.indexOf(column) === -1) {
2365 throw Error(`ParamError: specified column "${column}" not found in columns`);
2366 }
2367
2368 const columnValues = this.$getColumnData(column, false) as ArrayType1D
2369 const index = [...this.index]
2370
2371 const objToSort = columnValues.map((value, i) => {
2372 return { index: index[i], value }
2373 })
2374
2375 const sortedObjectArr = utils.sortObj(objToSort, ascending)
2376 const sortedIndex = sortedObjectArr.map(obj => obj.index)
2377
2378 const newDf = _loc({ ndFrame: this, rows: sortedIndex }) as DataFrame
2379
2380 if (inplace) {
2381 this.$setValues(newDf.values)
2382 this.$setIndex(newDf.index)
2383 } else {
2384 return newDf
2385 }
2386
2387 }
2388
2389 /**
2390 * Sets the index of the DataFrame to the specified value.

Callers

nothing calls this directly

Calls 7

$getColumnDataMethod · 0.95
_locFunction · 0.90
indexOfMethod · 0.80
sortObjMethod · 0.80
$setValuesMethod · 0.80
mapMethod · 0.65
$setIndexMethod · 0.65

Tested by

no test coverage detected