title: Assign label to categorical data in a table in PySpark
body: <p>I want to assign the label to the categorical numbers in a dataframe below using pyspark sql.</p>
  
  <p>In the MARRIAGE column 1=Married and 2=Unmarried. In the EDUCATION Column 1=Grad and 2=Undergrad</p>
  
  <pre>
  Current Dataframe:
  +--------+---------+-----+
  |MARRIAGE|EDUCATION|Total|
  +--------+---------+-----+
  |       1|        2|   87|
  |       1|        1|  123|
  |       2|        2|    3|
  |       2|        1|    8|
  +--------+---------+-----+
  </pre>
  
  <pre>
  Resulting Dataframe:
  +---------+---------+-----+
  |MARRIAGE |EDUCATION|Total|
  +---------+---------+-----+
  |Married  |Grad     |   87|
  |Married  |UnderGrad|  123|
  |UnMarried|Grad     |    3|
  |UnMarried|UnderGrad|    8|
  +---------+---------+-----+
  </pre>
  
  <p>Is it possible to assign the labels using a single udf and the withColumn()? Is there any way to assign in the single UDF by passing the whole dataframe and keep the column names as it is?</p>
  
  <p>I can think of a solution to do the operation on each column by using separate udfs as below. But can't figure out if there's a way to do together.</p>
  
  <pre><code>from pyspark.sql import functions as F
  
  def assign_marital_names(record):
      if record == 1:
          return "Married"
      elif record == 2:
          return "UnMarried"
  
  
  def assign_edu_names(record):
      if record == 1:
          return "Grad"
      elif record == 2:
          return "UnderGrad"
  
  assign_marital_udf = F.udf(assign_marital_names)
  assign_edu_udf = F.udf(assign_edu_names)
  df.withColumn("MARRIAGE", assign_marital_udf("MARRIAGE")).\
  withColumn("EDUCATION", assign_edu_udf("EDUCATION")).show(truncate=False)
  </code></pre>