title: How to count unique ID after groupBy in pyspark
body: <p>I'm using the following code to agregate students per year. The purpose is to know the total number of student for each year.</p>
  <pre><code>from pyspark.sql.functions import col
  import pyspark.sql.functions as fn
  gr = Df2.groupby(['Year'])
  df_grouped = 
  gr.agg(fn.count(col('Student_ID')).alias('total_student_by_year'))
  </code></pre>
  <p>The problem that I discovered that so many ID's are repeated, so the result is wrong and huge.</p>
  <p>I want to agregate the students by year, count the total number of student by year and avoid the repetition of ID's.</p>