title: Creating a column for a dataframe with exec() in pyspark is not working
body: <p>I have a dataframe with multiple columns, and I have created a code fragment to generate a new column 'label' which represents a string containing information of the rest of the columns.</p>
  
  <p>Imagine I have the next dataframe 'df':</p>
  
  <pre><code>+------------+------+
  | Atr0       | Atr1 |
  +------------+------+
  |     0      |  1   |
  +------------+------+
  |     0      |  2   |
  +------------+------+
  |     0      |  8   |
  +------------+------+
  |     ...    |  ... |
  +------------+------+
  </code></pre>
  
  <p>So, I want to create a new dataframe 'df' which is:</p>
  
  <pre><code>+------------+------+-------------------+
  | Atr0       | Atr1 |        Atr2       |  
  +------------+------+-------------------+
  |     0      |  1   | Atr0='0', Atr1='1'|
  +------------+------+-------------------+
  |     0      |  2   | Atr0='0', Atr1='2'|
  +------------+------+-------------------+
  |     0      |  8   | Atr0='0', Atr1='8'|
  +------------+------+-------------------+
  |     ...    |  ... |        ...        |
  +------------+------+-------------------+
  </code></pre>
  
  <p>If I execute the next code fragment it works:</p>
  
  <pre><code>df = df.withColumn('Atr2', concat(lit("Atr0="), col('Atr0'), lit(", Atr1="), col('Atr1'))
  </code></pre>
  
  <p>But I want the code not to be user dependant. I mean, I have a variable 'list' containing the columns of the dataframe, so I want to iterate that list in order to generate the new column automatically. Here the code I generated:</p>
  
  <pre><code>def addColumn(list):
  
      # Many operations to create the dataframe 'df'
      list = list + ['AtrX']
      # list is a variable containing ['Atr0', 'Atr1', 'AtrX']
      label = "df = df.withColumn('label', concat("
  
      count_aux = 0
      for atributo_aux in list:
          if(count_aux == 0):
              label = label + "lit('" + atributo_aux + "='), col('" + atributo_aux + "')" 
          else:
              label = label + ", lit('," + atributo_aux + "='), col('" + atributo_aux + "')"
          count_aux += 1
  
      label = label + "))" 
      print(label)
      exec(label)
  </code></pre>
  
  <p>But when I execute the function the dataframe is never updated. I checked if the string was correctly generated and it is. Why if I execute the code putting manually the column names it is perfectly updated, and in the code generated above not?</p>