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

Method drop

src/danfojs-base/core/frame.ts:2201–2322  ·  view source on GitHub ↗
(options?:
        {
            columns?: string | Array<string>,
            index?: Array<string | number>,
            inplace?: boolean
        }
    )

Source from the content-addressed store, hash-verified

2199 }
2200 ): DataFrame
2201 drop(options?:
2202 {
2203 columns?: string | Array<string>,
2204 index?: Array<string | number>,
2205 inplace?: boolean
2206 }
2207 ): DataFrame | void {
2208 let { columns, index, inplace } = { inplace: false, ...options }
2209
2210 if (!columns && !index) {
2211 throw Error('ParamError: Must specify one of columns or index');
2212 }
2213
2214 if (columns && index) {
2215 throw Error('ParamError: Can only specify one of columns or index');
2216 }
2217
2218 if (columns) {
2219 const columnIndices: Array<number> = []
2220
2221 if (typeof columns === "string") {
2222 columnIndices.push(this.columns.indexOf(columns))
2223 } else if (Array.isArray(columns)) {
2224 for (let column of columns) {
2225 if (this.columns.indexOf(column) === -1) {
2226 throw Error(`ParamError: specified column "${column}" not found in columns`);
2227 }
2228 columnIndices.push(this.columns.indexOf(column))
2229 }
2230
2231 } else {
2232 throw Error('ParamError: columns must be an array of column names or a string of column name');
2233 }
2234
2235 let newRowData: ArrayType2D = []
2236 let newColumnNames = []
2237 let newDtypes = []
2238
2239 for (let i = 0; i < this.values.length; i++) {
2240 const tempInnerArr = []
2241 const innerArr = this.values[i] as ArrayType1D
2242 for (let j = 0; j < innerArr.length; j++) {
2243 if (!(columnIndices.includes(j))) {
2244 tempInnerArr.push(innerArr[j])
2245 }
2246 }
2247 newRowData.push(tempInnerArr)
2248 }
2249
2250 for (let i = 0; i < this.columns.length; i++) {
2251 const element = this.columns[i]
2252 if (!(columns.includes(element))) {
2253 newColumnNames.push(element)
2254 newDtypes.push(this.dtypes[i])
2255 }
2256 }
2257
2258 if (inplace) {

Callers 1

setIndexMethod · 0.95

Calls 5

indexOfMethod · 0.80
includesMethod · 0.80
$setValuesMethod · 0.80
$setColumnNamesMethod · 0.65
$setIndexMethod · 0.65

Tested by

no test coverage detected