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

Method append

src/danfojs-base/core/frame.ts:3134–3214  ·  view source on GitHub ↗
(
        newValues: ArrayType1D | ArrayType2D | Series | DataFrame,
        index: Array<number | string> | number | string,
        options?: {
            inplace?: boolean,
        }
    )

Source from the content-addressed store, hash-verified

3132 }
3133 ): DataFrame
3134 append(
3135 newValues: ArrayType1D | ArrayType2D | Series | DataFrame,
3136 index: Array<number | string> | number | string,
3137 options?: {
3138 inplace?: boolean,
3139 }
3140 ): DataFrame | void {
3141 const { inplace } = { inplace: false, ...options }
3142
3143 if (!newValues) {
3144 throw Error(`ParamError: newValues must be a Series, DataFrame or Array`);
3145 }
3146
3147 if (!index) {
3148 throw Error(`ParamError: index must be specified`);
3149 }
3150
3151 let rowsToAdd = []
3152 if (newValues instanceof Series) {
3153
3154 if (newValues.values.length !== this.shape[1]) {
3155 throw Error(`ValueError: length of newValues must be the same as the number of columns.`);
3156 }
3157 rowsToAdd = [newValues.values]
3158
3159 } else if (newValues instanceof DataFrame) {
3160
3161 if (newValues.shape[1] !== this.shape[1]) {
3162 throw Error(`ValueError: length of newValues must be the same as the number of columns.`);
3163 }
3164 rowsToAdd = newValues.values
3165
3166 } else if (Array.isArray(newValues)) {
3167
3168 if (utils.is1DArray(newValues)) {
3169 rowsToAdd = [newValues]
3170 } else {
3171 rowsToAdd = newValues
3172 }
3173
3174 if ((rowsToAdd[0] as any).length !== this.shape[1]) {
3175 throw Error(`ValueError: length of newValues must be the same as the number of columns.`);
3176 }
3177
3178 } else {
3179 throw Error(`ValueError: newValues must be a Series, DataFrame or Array`);
3180 }
3181
3182
3183 let indexInArrFormat: Array<number | string> = []
3184 if (!Array.isArray(index)) {
3185 indexInArrFormat = [index]
3186 } else {
3187 indexInArrFormat = index
3188 }
3189
3190 if (rowsToAdd.length !== indexInArrFormat.length) {
3191 throw Error(`ParamError: index must contain the same number of values as newValues`);

Callers

nothing calls this directly

Calls 3

is1DArrayMethod · 0.80
$setValuesMethod · 0.80
$setIndexMethod · 0.65

Tested by

no test coverage detected