title: Populate distinct of column based on another column in PySpark
body: <p>I have a data frame like below in PySpark. I want to select <code>serial_num</code>, <code>devicetype</code>, <code>device_model</code> and <code>distinct of timestamp for each serial_num</code> from the below dataframe:</p>
  
  <pre><code>+-------------+-----------------+---------------+------------------------+
  | serial_num  |   devicetype    | device_model  |        timestamp       |
  +-------------+-----------------+---------------+------------------------+
  | 58172A0396  |                 |               | 2003-01-02 17:37:15.0  |
  | 58172A0396  |                 |               | 2003-01-02 17:37:15.0  |
  | 46C5Y00693  | Mac Pro         | Mac PC        | 2018-01-03 17:17:23.0  |
  | 1737K7008F  | Windows PC      | Windows PC    | 2018-01-05 11:12:31.0  |
  | 1737K7008F  | Network Device  | Unknown       | 2018-01-05 11:12:31.0  |
  | 1737K7008F  | Network Device  | Unknown       | 2018-01-05 11:12:31.0  |
  | 1737K7008F  | Network Device  |               | 2018-01-06 03:12:52.0  |
  | 1737K7008F  | Windows PC      | Windows PC    | 2018-01-06 03:12:52.0  |
  | 1737K7008F  | Network Device  | Unknown       | 2018-01-06 03:12:52.0  |
  | 1665NF01F3  | Network Device  | Unknown       | 2018-01-07 03:42:34.0  |
  +----------------+-----------------+---------------+---------------------+
  </code></pre>
  
  <p>I have tried like below</p>
  
  <pre><code>df1 = df.select('serial_num', 'devicetype', 'device_model', f.count('distinct timestamp').over(Window.partitionBy('serial_num')).alias('val')
  </code></pre>
  
  <p>The result I want is:</p>
  
  <pre><code>+-------------+-----------------+---------------+-----+
  | serial_num  |   devicetype    | device_model  |count|
  +-------------+-----------------+---------------+-----+
  | 58172A0396  |                 |               |  1  |
  | 58172A0396  |                 |               |  1  |
  | 46C5Y00693  | Mac Pro         | Mac PC        |  1  |
  | 1737K7008F  | Windows PC      | Windows PC    |  2  |
  | 1737K7008F  | Network Device  | Unknown       |  2  |
  | 1737K7008F  | Network Device  | Unknown       |  2  |
  | 1737K7008F  | Network Device  |               |  2  |
  | 1737K7008F  | Windows PC      | Windows PC    |  2  |
  | 1737K7008F  | Network Device  | Unknown       |  2  |
  | 1665NF01F3  | Network Device  | Unknown       |  1  |
  +-------------+-----------------+---------------+-----+
  </code></pre>
  
  <p>How can I achieve that?</p>