danfojs icon indicating copy to clipboard operation
danfojs copied to clipboard

dropNa not working

Open jaycoolslm opened this issue 1 year ago • 3 comments

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

jaycoolslm avatar Mar 31 '24 17:03 jaycoolslm

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?

aniketkumar7 avatar Apr 04 '24 03:04 aniketkumar7

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

jaycoolslm avatar Apr 05 '24 18:04 jaycoolslm

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.

aniketkumar7 avatar Apr 06 '24 02:04 aniketkumar7