MCPcopy Create free account
hub / github.com/javascriptdata/danfojs / map

Method map

src/danfojs-base/core/series.ts:999–1026  ·  view source on GitHub ↗
(callable: mapParam, options?: { inplace?: boolean })

Source from the content-addressed store, hash-verified

997 */
998 map(callable: mapParam, options?: { inplace?: boolean }): Series
999 map(callable: mapParam, options?: { inplace?: boolean }): Series | void {
1000 const { inplace } = { inplace: false, ...options }
1001
1002 const isCallable = utils.isFunction(callable);
1003
1004 const data = (this.values as ArrayType1D).map((val: any, i: number) => {
1005 if (isCallable) {
1006 return (callable as Function)(val, i);
1007 } else if (utils.isObject(callable)) {
1008 if (val in callable) {
1009 //@ts-ignore
1010 return callable[val];
1011 } else {
1012 return val
1013 }
1014 } else {
1015 throw new Error("Param Error: callable must either be a function or an object");
1016 }
1017 });
1018
1019 if (inplace) {
1020 this.$setValues(data)
1021 } else {
1022 const sf = this.copy();
1023 sf.$setValues(data)
1024 return sf;
1025 }
1026 }
1027
1028 /**
1029 * Applies a function to each element of a Series

Callers

nothing calls this directly

Calls 5

copyMethod · 0.95
isFunctionMethod · 0.80
isObjectMethod · 0.80
$setValuesMethod · 0.80
mapMethod · 0.65

Tested by

no test coverage detected