title: Pyspark UDF to round one column to the precision specified by another column
body: <p>I am trying to make a UDF in pyspark to round one column to the precision specified, in each row, by another column, e.g., the following dataframe:</p>
  
  
  
  <pre class="lang-py prettyprint-override"><code>+--------+--------+
  |    Data|Rounding|
  +--------+--------+
  |3.141592|       3|
  |0.577215|       1|
  +--------+--------+
  </code></pre>
  
  <p>when submitted to said UDF should give the following result:</p>
  
  <pre class="lang-py prettyprint-override"><code>+--------+--------+--------------+
  |    Data|Rounding|Rounded Column|
  +--------+--------+--------------+
  |3.141592|       3|         3.142|
  |0.577215|       1|           0.6|
  +--------+--------+--------------+
  </code></pre>
  
  <p>In particular, I have tried the following code:</p>
  
  <pre class="lang-py prettyprint-override"><code>import pandas as pd
  from pyspark.sql import SparkSession
  from pyspark.sql.types import StructType, StructField, FloatType, LongType, 
  IntegerType
  
  pdDF = pd.DataFrame(columns=["Data", "Rounding"], data=[[3.141592, 3], 
     [0.577215, 1]])
  
  mySchema = StructType([ StructField("Data", FloatType(), True), 
  StructField("Rounding", IntegerType(), True)])
  
  spark = SparkSession.builder.master("local").appName("column 
  rounding").getOrCreate()
  
  df = spark.createDataFrame(pdDF,schema=mySchema)
  
  df.show()
  
  def round_column(Data, Rounding):
  return (lambda (Data, Rounding): round(Data, Rounding), FloatType())
  
  spark.udf.register("column rounded to the precision specified by another", 
  round_column, FloatType())
  
  
  df_rounded = df.withColumn('Rounded Column', round_column(df["Data"], 
  df["Rounding"]))
  
  df_rounded .show()
  </code></pre>
  
  <p>but I get the following error:</p>
  
  <pre class="lang-py prettyprint-override"><code>Traceback (most recent call last):
    File "whatever.py", line 21, in &lt;module&gt;
      df_redondeado = df.withColumn('columna_redondeada',round_column(df["Data"], df["Rounding"]))
    File "whomever\spark\spark-2.3.1-bin-hadoop2.7\python\pyspark\sql\dataframe.py", line 1848, in withColumn
      assert isinstance(col, Column), "col should be Column"
  AssertionError: col should be Column
  </code></pre>
  
  <p>Any help would be deeply appreciated :)</p>