danfojs icon indicating copy to clipboard operation
danfojs copied to clipboard

df apply not working as expected

Open RahulDas-dev opened this issue 1 year ago • 1 comments

Describe the bug df apply not working as expected

To Reproduce Here is the code for reproduce the bug

let data = {
    "text": ['THIS','IS', 'IN','UPPERCASE'],
    "count": [34, -4, 5, 0],
    "rank": [20, 2, 30, 8]
}
let df = new dfd.DataFrame(data)
df.print()

df['text'].apply(x => x.toLowerCase(), {inplace:true})  // It should change the df['text'] to upper case
df.print()

Expected behavior df['colums'].apply(x => x +1 , {inplace:true}) should mutate the coulmn according to lambda in apply, but it is not doing so.

Screenshots image

Desktop (please complete the following information):

  • OS: [Windows]
  • Browser [chrome]
  • Version [1.1.2]

Additional context

df['text'] = df['text'].apply(x =>x.toLowerCase()) working correctly.

image

RahulDas-dev avatar Feb 23 '24 14:02 RahulDas-dev

@RahulDas-dev Good point. atm, this won't work because of how we handle selection by subsetting. In danfojs, when you do df['text'], it returns a copy of the Series, not a reference. So even though you're using inplace=true, you're modifying a copy, not the original DataFrame column.

We can look at improving this in the future

risenW avatar Apr 02 '25 16:04 risenW