Home > Back-end >  Fill na cells in one column with another column in Excel
Fill na cells in one column with another column in Excel

Time:04-26

Given an excel sample data as follows:

enter image description here

For NA cells in column B (which means B3 and B5), I'll need to fill with values in column A.

enter image description here

I write a simple formula for cell B3: =IF(ISNA(B3),A3,B3) (equivalent to df['b'].fillna(df['a']) in Pandas), but returns 0. How could I write a proper formula to solve this issue? Thanks.

The expected result should be like this:

enter image description here

CodePudding user response:

A cell can contain either a value or a formula, which is why you should create an extra column for the result. NA in excel is an error code and does not indicate that a cell is blank. You should use the formula =IF(ISBLANK(B3),A3,B3) in column C

CodePudding user response:

I think you get the "Circular dependency detected" error. The easy solution is:

  1. copy the column b in the column c
  2. fill the na value in the column c with the formula that you defined
  • Related