title: pySpark - get max value row in a rolling window
body: <p>I have a pyspark dataframe, with below sample rows. I'm trying to get max avg value in a span of 10 minutes. I am trying to use Window functions, but not able to achieve the result.</p>
  
  <p>Here is my dataframe with random data for 30 minutes. I am expecting 3 rows to be the output, 1 row for each 10 minutes.</p>
  
  <pre><code>+-------------------+---------+
  |         event_time|avg_value|
  +-------------------+---------+
  |2019-12-29 00:01:00|      9.5|
  |2019-12-29 00:02:00|      9.0|
  |2019-12-29 00:04:00|      8.0|
  |2019-12-29 00:06:00|     21.0|
  |2019-12-29 00:08:00|      7.0|
  |2019-12-29 00:11:00|      8.5|
  |2019-12-29 00:12:00|     11.5|
  |2019-12-29 00:14:00|      8.0|
  |2019-12-29 00:16:00|     31.0|
  |2019-12-29 00:18:00|      8.0|
  |2019-12-29 00:21:00|      8.0|
  |2019-12-29 00:22:00|     16.5|
  |2019-12-29 00:24:00|      7.0|
  |2019-12-29 00:26:00|     14.0|
  |2019-12-29 00:28:00|      7.0|
  +-------------------+---------+
  </code></pre>
  
  <p>I am using the below code for that</p>
  
  <pre><code>window_spec = Window.partitionBy('event_time').orderBy('event_time').rangeBetween(-60*10,0)
  new_df = data.withColumn('rank', rank().over(window_spec))
  new_df.show()
  </code></pre>
  
  <p>but this code is giving me the below error:</p>
  
  <pre><code>pyspark.sql.utils.AnalysisException: 'Window Frame specifiedwindowframe(RangeFrame, -600, currentrow$()) must match the required frame specifiedwindowframe(RowFrame, unboundedpreceding$(), currentrow$());'
  </code></pre>
  
  <p>My desired output is</p>
  
  <pre><code>+-------------------+---------+
  |         event_time|avg_value|
  +-------------------+---------+
  |2019-12-29 00:06:00|     21.0|
  |2019-12-29 00:16:00|     31.0|
  |2019-12-29 00:22:00|     16.5|
  +-------------------+---------+
  </code></pre>
  
  <p>Can someone please help me on this?</p>
  
  <p>TIA.</p>