1

I am working extensive data processing in nodejs. I found danfojs as a nice alternative to python Pandas. But facing some functionality lacking in comparison to Pandas.

How to work out pandas isin() functionality in Danfojs ?

Example:

I have the below DataFrame:

id name address
asefwc Abdullah Cumilla
wefcss Khairul Jashore
erfegf Jaman Magura
ytttte Najrul Nowga
edqfgh Latif Chattagram
yutydg Majhar Rajshahi

And the below Series:

id
wefcss
ytttte
yutydg

I want to get those rows of the Dataframe which id exists in the series

Shamim
  • 635
  • 2
  • 12
  • 28

2 Answers2

1

I don't think there is an equivalent of pandas 'isin' but I've found a work around to solve 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 is your Series
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}) 
shirish kumar
  • 47
  • 1
  • 4
-1

I think it's worthy to explore dfd.DataFrame.merge, dfd.DataFrame.merge, basically, choosing an specific join variant you are filtering data in an specific way.