danfojs icon indicating copy to clipboard operation
danfojs copied to clipboard

Error when using .eq with Array

Open joshuakoh1 opened this issue 3 years ago • 2 comments

Code

const filters = [1, 2, 3, 4, 5];
console.log(filters);
return df.query(df.colA.eq(filters));

Output

(5) [1, 2, 3, 4, 5]        
Uncaught Error: LengthError: length of other must be equal to length of Series

joshuakoh1 avatar May 01 '22 14:05 joshuakoh1

same problem with df = df.loc({ rows: df['id'].eq(['a', 'b']) }) I wonder if this library is missing an option to filter with an array

shrshk avatar Jun 05 '22 17:06 shrshk

same problem with df = df.loc({ rows: df['id'].eq(['a', 'b']) }) I wonder if this library is missing an option to filter with an array

I've found a work around to this problem

`const dfd = require("danfojs-node") const data = [ ['asefwc', 'Abdullah', 'Cumilla'], ['wefcss', 'Khairul', 'Jashore'], ['erfegf', 'Jaman', 'Magura'] ]

const columns = ['id', 'name', 'address']

let df = new dfd.DataFrame(data, { columns })

let ids = df['id'].values // get all the column values

let allRowsToInclude = []

idsToInclude.forEach((idToInclude) => { const rowsToInclude = ids.flatMap((id, idx) => id === idToInclude ? idx : []) allRowsToInclude = allRowsToInclude.push(... rowsToInclude) }

// creates a new df with filtered rows let dfFinal = df.loc({rows: allRowsToInclude}) `

shrshk avatar Jun 05 '22 18:06 shrshk

Code

const filters = [1, 2, 3, 4, 5];
console.log(filters);
return df.query(df.colA.eq(filters));

Output

(5) [1, 2, 3, 4, 5]        
Uncaught Error: LengthError: length of other must be equal to length of Series

From the error message, it looks like the length of df.colA. and filter is not the same. They must be the same for `.eq. to work.

risenW avatar Sep 25 '22 11:09 risenW