title: PySpark: How to check if a column contains a number using isnan
body: <p>I have a dataframe which looks like this:</p>
  
  <pre><code>+------------------------+----------+
  |Postal code             |PostalCode|
  +------------------------+----------+
  |Muxía                   |null      |
  |Fuensanta               |null      |
  |Salobre                 |null      |
  |Bolulla                 |null      |
  |33004                   |null      |
  |Santa Eulàlia de Ronçana|null      |
  |Cabañes de Esgueva      |null      |
  |Vallarta de Bureba      |null      |
  |Villaverde del Monte    |null      |
  |Villaluenga del Rosario |null      |
  +------------------------+----------+
  </code></pre>
  
  <p>If the Postal code column contains only numbers, I want to create a new column where only numerical postal codes are stored. If the postal code column contains only text, want to create an new column called 'Municipality'.</p>
  
  <p>I tried to use 'isnan' as my understanding this will check if a value is not a number, but this does not seem to work. Should the column type be string for this to work or?</p>
  
  <p>So far my attempt are: </p>
  
  <pre><code>&gt; df2 = df.withColumn('PostalCode', when(isnan(df['Postal code']), df['Postal code']) 
  </code></pre>
  
  <p>Looking at the dataframe results example posted above, you can see all values 'Null' are returned for new column, also for postal code '33004'</p>
  
  <p>Any ideas will be much appreciated</p>