title: Monthly Aggregation in pyspark
body: <p>I'm looking for a way to aggregate by month my data. I want firstly to keep only month in my visitdate. My DataFrame looks like this:</p>
  
  <pre><code>Row(visitdate = 1/1/2013, 
  patientid = P1_Pt1959, 
  amount = 200, 
  note = jnut, 
  ) 
  </code></pre>
  
  <p>My objectif subsequently is to group by visitdate and calculate the sum of amount. I tried this :</p>
  
  <pre><code>from pyspark.sql import SparkSession
  
  spark = SparkSession \
  .builder \
  .appName("Python Spark SQL basic example") \
  .config("spark.some.config.option", "some-value") \
  .getOrCreate()
  
  file_path = "G:/Visit Data.csv"
  patients = spark.read.csv(file_path,header = True)
  patients.createOrReplaceTempView("visitdate")
  
  sqlDF = spark.sql("SELECT visitdate,SUM(amount) as totalamount from visitdate GROUP BY visitdate")
  sqlDF.show()
  </code></pre>
  
  <p>This is the result :</p>
  
  <pre><code>visitdate|totalamount|
  +----------+-----------+
  |  9/1/2013|    10800.0|
  |25/04/2013|    12440.0|
  |27/03/2014|    16930.0|
  |26/03/2015|    18560.0|
  |14/05/2013|    13770.0|
  |30/06/2013|    13880.0
  </code></pre>
  
  <p>My objectif is to get something like this:</p>
  
  <pre><code>  visitdate|totalamount|
  +----------+-----------+
  |1/1/2013|    10800.0|
  |1/2/2013|    12440.0|
  |1/3/2013|    16930.0|
  |1/4/2014|    18560.0|
  |1/5/2015|    13770.0|
  |1/6/2015|    13880.0|
  </code></pre>