javascriptdata / danfojs

Danfo.js is an open source, JavaScript library providing high performance, intuitive, and easy to use data structures for manipulating and processing structured data.
https://danfo.jsdata.org/
MIT License
4.81k stars 209 forks source link

dropNa not working #637

Open jaycoolslm opened 7 months ago

jaycoolslm commented 7 months ago

I am importing an excel file which contains an undefined field:

// read the excel file
  let df = (await dfd.readExcel(local_xcel)) as DataFrame;
  if (test) {
    df = df.head(testAmount);
  }
  console.log("Initial Dataframe");
  df.iloc({ rows: ["15:18"] }).print();

  console.log(df.shape);

  let df_drop = df.dropNa({ axis: 1 });
  df_drop
    .iloc({ rows: ["15:18"] })
    .isNa()
    .print();
  console.log(df_drop.shape);

this code is not removing the undefined row, even though it is identifying it as undefined when using the .isNa() mask

aniketkumar7 commented 7 months ago

I think this might works :

The line df = df.dropna({ axis: 0, how: 'any' }) will remove any rows that have at least one undefined value.

  1. The axis: 0 parameter specifies that we’re dropping rows.
  2. The how: 'any' parameter ensures that any row containing at least one undefined value will be dropped.

Can I contribute to it if this works?

jaycoolslm commented 7 months ago

Hi @aniketkumar7,

I get this error when trying that how property

Object literal may only specify known properties, and 'how' does not exist in type '{ axis: 0 | 1; inplace?: boolean | undefined; }'.

doesn't seem to be implemented

aniketkumar7 commented 7 months ago

Yes, you are right, It seems that the "how" property is not available in the version of DataFrame.

Try after removing the how property and directly applied df.dropna({ axis: 0 }) to drop rows with any null value. I think this should work as expected.