title: Creating a row number of each row in PySpark DataFrame using row_number() function with Spark version 2.2
body: <p>I am having a PySpark DataFrame -</p>
  
  <pre><code>valuesCol = [('Sweden',31),('Norway',62),('Iceland',13),('Finland',24),('Denmark',52)]
  df = sqlContext.createDataFrame(valuesCol,['name','id'])
  +-------+---+
  |   name| id|
  +-------+---+
  | Sweden| 31|
  | Norway| 62|
  |Iceland| 13|
  |Finland| 24|
  |Denmark| 52|
  +-------+---+
  </code></pre>
  
  <p>I wish to add a row column to this DataFrame, which is the row number (serial number) of the row, like shown below -</p>
  
  <p><strong>My final output should be:</strong></p>
  
  <pre><code>+-------+---+--------+
  |   name| id|row_num |
  +-------+---+--------+
  | Sweden| 31|       1|
  | Norway| 62|       2|
  |Iceland| 13|       3|
  |Finland| 24|       4|
  |Denmark| 52|       5|
  +-------+---+--------+
  </code></pre>
  
  <p>My Spark version is <code>2.2</code></p>
  
  <p>I am trying this code, but it doesn't work -</p>
  
  <pre><code>from pyspark.sql.functions import row_number
  from pyspark.sql.window import Window
  w = Window().orderBy()
  df = df.withColumn("row_num", row_number().over(w))
  df.show()
  </code></pre>
  
  <p>I am getting an Error:</p>
  
  <pre><code>AnalysisException: 'Window function row_number() requires window to be ordered, please add ORDER BY clause. For example SELECT row_number()(value_expr) OVER (PARTITION BY window_partition ORDER BY window_ordering) from table;'
  </code></pre>
  
  <p>If I understand it correctly, I need to order some column, but I don't want something like this <code>w = Window().orderBy('id')</code> because that will reorder the entire DataFrame.</p>
  
  <p>Can anyone suggest how to achieve the above mentioned output using <code>row_number()</code> function?</p>