title: Extracting the year from Date in Pyspark dataframe
body: <p>I have a Pyspark data frame that contains a date column "Reported Date"(type:string). I would like to get the count of another column after extracting the year from the date.</p>
  
  <p>I can get the count if I use the string date column.</p>
  
  <pre><code>crimeFile_date.groupBy("Reported Date").sum("Offence Count").show()
  </code></pre>
  
  <p>and I get this output</p>
  
  <pre><code>+-------------+------------------+
  |Reported Date|sum(Offence Count)|
  +-------------+------------------+
  |   13/08/2010|               342|
  |    6/10/2011|               334|
  |   27/11/2011|               269|
  |   12/01/2012|               303|
  |   22/02/2012|               286|
  |   31/07/2012|               276|
  |   25/04/2013|               222|
  +-------------+------------------+
  </code></pre>
  
  <p>To extract the year from "Reported Date" I have converted it to a date format (<a href="https://stackoverflow.com/questions/38080748/convert-pyspark-string-to-date-format/38081786#38081786">using this approach</a>) and named the column "Date". 
  However, when I try to use the same code to group by the new column and do the count I get an error message.</p>
  
  <pre><code>crimeFile_date.groupBy(year("Date").alias("year")).sum("Offence Count").show()
  </code></pre>
  
  <pre><code>TypeError: strptime() argument 1 must be str, not None
  </code></pre>
  
  <p>This is the data schema:</p>
  
  <pre><code>root
   |-- Offence Count: integer (nullable = true)
   |-- Reported Date: string (nullable = true)
   |-- Date: date (nullable = true)
  </code></pre>
  
  <p>Is there a way to fix this error? or extract the year using another method?
  Thank you</p>