title: How to fill nan values based on two other columns?
body: <p>Let's say you have the following df:</p>
  <pre><code>     VAT       taxrate#1    taxrate#2    taxrate#3    taxrate#4    ExclVAT
  --  -------  -----------  -----------  -----------  -----------  ---------
   0    19.95           21          nan          nan          nan      95
   2     0               0            0            0          nan     nan
   6     3.15          nan           21          nan          nan      15
   9   125.34           21          nan          nan          nan     596.86
  11   540.69           21          nan          nan          nan    2574.73
  13   254.31           21          nan          nan          nan    1211
  15  1378.94          nan          nan          nan          nan    6566.36
  18   401.65          nan          nan          nan          nan    1912.6
  20    58.84          nan          nan          nan          nan     264.18
  22    17.85           21          nan          nan          nan      85
  24    16.38           21           21           21          nan      77.98
  28   252              21           21          nan          nan    1200
  31     6.24           21          nan          nan          nan      29.73
  33    60.9            21           21          nan          nan     290
  36    60.9            21           21          nan          nan     290
  39    75.6            21           21          nan          nan     360
  </code></pre>
  <p>I need code that calculates the VAT amount if all taxrate values are NaN.</p>
  <p>The VAT can be calculated and inserted in taxrate#1. VAT can be either 21%, 9% or 0%.</p>
  <p>How to achieve this?</p>
  <p>Desired output:</p>
  <pre><code>     VAT       taxrate#1    taxrate#2    taxrate#3    taxrate#4    ExclVAT
  --  -------  -----------  -----------  -----------  -----------  ---------
   0    19.95           21          nan          nan          nan      95
   2     0               0            0            0          nan     nan
   6     3.15          nan           21          nan          nan      15
   9   125.34           21          nan          nan          nan     596.86
  11   540.69           21          nan          nan          nan    2574.73
  13   254.31           21          nan          nan          nan    1211
  15  1378.94           21          nan          nan          nan    6566.36
  18   401.65           21          nan          nan          nan    1912.6
  20    58.84          nan          nan          nan          nan     264.18
  22    17.85           21          nan          nan          nan      85
  24    16.38           21           21           21          nan      77.98
  28   252              21           21          nan          nan    1200
  31     6.24           21          nan          nan          nan      29.73
  33    60.9            21           21          nan          nan     290
  36    60.9            21           21          nan          nan     290
  39    75.6            21           21          nan          nan     360
  </code></pre>
  <p>I've tried the following code:</p>
  <pre><code>cols_to_check = ['taxrate#1', 'taxrate#2','taxrate#3']
  dftaxitems['is_na'] = dftaxitems[cols_to_check].isnull().apply(lambda x: all(x), axis=1) 
  dftaxitems
  
  for i, row in dftaxitems.iterrows():
      if dftaxitems['is_na'][i] == True:
          dftaxitems['taxrate#1'] = dftaxitems['taxrate#1'].fillna((dftaxitems['BTW'].astype(float) / dftaxitems['ExclBTW'].astype(float)) * 100)
          
  def custom_round(x, base=3):
      return int(base * round(float(x)/base))
  dftaxitems['taxrate#1'] = dftaxitems['taxrate#1'].apply(lambda x: custom_round(x, base=3))
  dftaxitems
  </code></pre>
  <p>However, this will lead to not rounding to 21, 9 or 0 or else np.nan.</p>
  <p>I want the calculated amount to be exactly 21,9 or 0 and else a np.nan.</p>
  <p>Now the code will round to the nearest table of 3 w/o looking at how close the value is to 21,9 or 0.</p>
  <p>My question is:
  How to assign 21%, 9% or 0% to taxrate#1 when dividing VAT by ExclVAT to calculate the VAT % and add it to taxrate #1.</p>
  <p>Sorry if this is all a bit un-cohesive, I've worked for too long.
  Please help!</p>