title: Handling NaN Values in Pandas with Conditional Statement
body: <p>I'm working with some data where the customer postcode data is invalid. As a result I'm not able to map the CountryISOCode to their postcode resulting in a NaN. However, I have noticed that for all CountryISOCodes with NaN, the CurrencyCode can provide me with enough to fix the problem for now.</p>
  
  <p>I've gone to various Stackoverflow articles but I cannot find the solution to my problem. I've tried...</p>
  
  <pre><code>def func(row):
      if row['CountryISOCode'] == np.nan &amp; row['Currency'] == 'EUR':
          return 'IRE'
  elif row['CountryISOCode'] == np.nan &amp; row['Currency'] == 'GBP':
      return 'GBR'
  else:
      return row['CountryISOCode']
  
  df['CountryISOCode'] = df.apply(func, axis=1)
  </code></pre>
  
  <p>and some other methods but to no avail...</p>
  
  <p>Below I have provided a replication of the data I'm working with</p>
  
  <pre><code>import pandas as pd
  import numpy as np
  
  data = [
      ['Steve', 'Invalid Postcode', 'GBP', np.nan ],
      ['Robyn', 'Invalid Postcode', 'EUR', np.nan],
      ['James', 'Valid Postcode', 'GBP', 'GBR'],
      ['Halo', 'Invalid Postcode', 'EUR', np.nan],
      ['Jesus', 'Valid Postcode', 'GBP', 'GBR']
      ]
  
  df = pd.DataFrame(columns=["Name", "PostCode", "CurrencyCode", "CountryISOCode"], data=data)
  </code></pre>
  
  <p>Essentially if I was working with SQL my code would be as follows.</p>
  
  <pre><code>IF countryISOCode IS NULL 
      AND currency = ‘GBP’ 
  THEN CountryISOCode =  ‘GBR’
  ELSE
  IF countryISOCode IS NULL 
      AND currency = ‘EUR 
  THEN CountryISOCode =  ‘IRE’
  ELSE countryISOCode 
  END
  </code></pre>
  
  <p>Any ideas?</p>