title: How to convert date to the first day of month in a PySpark Dataframe column?
body: <p>I have the following DataFrame: </p>
  
  <pre><code>+----------+
  |      date|
  +----------+
  |2017-01-25|
  |2017-01-21|
  |2017-01-12|
  +----------+
  </code></pre>
  
  <p>Here is the code the create above DataFrame: </p>
  
  <pre><code>import pyspark.sql.functions as f
  rdd = sc.parallelize([("2017/11/25",), ("2017/12/21",), ("2017/09/12",)])
  df = sqlContext.createDataFrame(rdd, ["date"]).withColumn("date", f.to_date(f.col("date"), "yyyy/MM/dd"))
  df.show()
  </code></pre>
  
  <p>I want a new column with the first date of month for each row, just replace the day to "01" in all the dates</p>
  
  <pre><code>+----------++----------+
  |      date| first_date|
  +----------++----------+
  |2017-11-25| 2017-11-01|
  |2017-12-21| 2017-12-01|
  |2017-09-12| 2017-09-01|
  +----------+-----------+
  </code></pre>
  
  <p>There is a last_day function in PySpark.sql.function, however, there is no first_day function. </p>
  
  <p>I tried using date_sub to do this but did not work: I get a column not Iterable error because the second argument to date_sub cannot be a column and has to be an integer. </p>
  
  <pre><code>f.date_sub(f.col('date'), f.dayofmonth(f.col('date')) - 1 )
  </code></pre>