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

Method fillNa

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

Source from the content-addressed store, hash-verified

2093 }
2094 ): DataFrame
2095 fillNa(
2096 values: number | string | boolean | ArrayType1D,
2097 options?:
2098 {
2099 columns?: Array<string>,
2100 inplace?: boolean
2101 }
2102 ): DataFrame | void {
2103 let { columns, inplace } = { inplace: false, ...options }
2104
2105 if (!values && typeof values !== "boolean" && typeof values !== "number" && typeof values !== "string") {
2106 throw Error('ParamError: value must be specified');
2107 }
2108
2109 if (Array.isArray(values)) {
2110 if (!Array.isArray(columns)) {
2111 throw Error('ParamError: value is an array, hence columns must also be an array of same length');
2112 }
2113
2114 if (values.length !== columns.length) {
2115 throw Error('ParamError: specified column and values must have the same length');
2116 }
2117
2118 columns.forEach((col) => {
2119 if (!this.columns.includes(col)) {
2120 throw Error(
2121 `ValueError: Specified column "${col}" must be one of ${this.columns}`
2122 );
2123 }
2124 });
2125 }
2126
2127 const newData = []
2128 const oldValues = [...this.values]
2129
2130 if (!columns) {
2131 //Fill all columns
2132 for (let i = 0; i < oldValues.length; i++) {
2133 const valueArr = [...oldValues[i] as ArrayType1D]
2134
2135 const tempArr = valueArr.map((innerVal) => {
2136 if (utils.isEmpty(innerVal)) {
2137 const replaceWith = Array.isArray(values) ? values[i] : values
2138 return replaceWith
2139 } else {
2140 return innerVal
2141 }
2142 })
2143 newData.push(tempArr)
2144 }
2145
2146 } else {
2147 //Fill specific columns
2148 const tempData = [...this.values]
2149
2150 for (let i = 0; i < tempData.length; i++) {
2151 const valueArr = tempData[i] as ArrayType1D
2152

Callers

nothing calls this directly

Calls 5

includesMethod · 0.80
isEmptyMethod · 0.80
indexOfMethod · 0.80
$setValuesMethod · 0.80
mapMethod · 0.65

Tested by

no test coverage detected