0

I am trying to replace the values of my second dataframe ('area') with those of my first dataframe ('test').

Image of my inputs:

enter image description here

The catch is that I only want to replace the values that are not NaN, so, for example, area.iloc[0,1] will be "6643.68" rather than "3321.84" but area.iloc[-2,-1] will be "19.66" rather than "NaN". I would have thought I could do something like:

area.loc[test.notnull()] = test

or

area.replace(area.loc[test.notnull()], test.notnull())

But this gives me the error "Cannot index with multidimensional key". Any ideas? This should be simple.

Anurag Dabas
  • 23,866
  • 9
  • 21
  • 41
  • This seems a case of using `.update()` rather than using `fillna()`. Anyway, there is an answer in the link that marked this post dup. – SeaBean May 14 '21 at 05:52

1 Answers1

0

Use fillna like:

area.fillna(test)
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252