title: Aggregating data at feature and time both
body: <p>I have a pyspark dataframe at 10 minute interval, how I can aggregate it at one categorical feature and at the time of 2 hours and then calculate the average of other two features and first value of third feature</p>
  
  <p>My sample data looks like follows in pyspark. I want to group by on 'ind' and at the time of 2 hours on 'date' and then calculate the mean of 'sal' and the first value of 'imp'</p>
  
  <pre><code>from pyspark import SparkContext
  from pyspark.sql import SQLContext
  
  sc = SparkContext.getOrCreate()
  sqlContext = SQLContext(sc)
  
   a = sqlContext.createDataFrame([["Anand", "2020-02-01 16:00:00", 12, "ba"], 
                              ["Anand", "2020-02-01 16:10:00", 14,"sa"], 
                              ["Carl", "2020-02-01 16:00:00", 16,"da"], 
                              ["Carl", "2020-02-01 16:10:00", 12,"ga"],
                              ["Eric", "2020-02-01 16:o0:00", 24, "sa"]], ['ind', "date","sal","imp"])
  a.show()
  
  |  ind|               date|sal|imp|
  +-----+-------------------+---+---+
  |Anand|2020-02-01 16:00:00| 12| ba|
  |Anand|2020-02-01 16:10:00| 14| sa|
  | Carl|2020-02-01 16:00:00| 16| da|
  | Carl|2020-02-01 16:10:00| 12| ga|
  | Eric|2020-02-01 16:o0:00| 24| sa|
  </code></pre>
  
  <p>I have no idea how I can mix category feature and time(2hrs) in groupby Pyspark. I know how to do it in Pandas. But my real data is huge. Any Suggestions?</p>