title: PySpark : KeyError when converting a DataFrame column of String type to Double
body: <p>I'm trying to learn machine learning with <code>PySpark</code>. I have a dataset that has a couple of <code>String</code> columns which have either <code>True or False or Yes or No</code> as its value. I'm working with <code>DecisionTree</code> and I wanted to convert these <code>String</code> values to corresponding <code>Double</code> values i.e. <code>True, Yes</code> should change to <code>1.0</code> and <code>False, No</code> should change to <code>0.0</code>. I saw a tutorial where they did the same thing and I came up with this code</p>
  
  <pre><code>df = sqlContext.read.csv("C:/../churn-bigml-20.csv",inferSchema=True,header=True)
  
  from pyspark.sql.types import DoubleType
  from pyspark.sql.functions import UserDefinedFunction
  
  binary_map = {'Yes':1.0, 'No':0.0, 'True':1.0, 'False':0.0}
  toNum = UserDefinedFunction(lambda k: binary_map[k], DoubleType())
  
  csv_data = df.drop('State').drop('Area code') \
      .withColumn('Churn', toNum(df['Churn'])) \
      .withColumn('International plan', toNum(df['International plan'])) \
      .withColumn('Voice mail plan', toNum(df['Voice mail plan'])).cache()
  </code></pre>
  
  <p>However when I run this, I get so many errors that look like this.</p>
  
  <pre><code>  File "C:\..\spark-2.1.0\python\lib\pyspark.zip\pyspark\worker.py", line 70, in &lt;lambda&gt;
    File "C:\..\workspace\PyML\src\ModelBuilding.py", line 20, in &lt;lambda&gt;
      toNum = UserDefinedFunction(lambda k: binary_map[k], DoubleType())
  KeyError: False
  </code></pre>
  
  <p><strong>Note</strong>: I'm working on PySpark with Spark 2.1 and Python 3.5 and I guess the tutorial that I follow uses spark 1.6 and Python 2.7. So I don't if this is one of the Python grammar issues.</p>