title: Python / Pyspark - Correct method chaining order rules
body: <p>Coming from a SQL development background, and currently learning pyspark / python I am a bit confused with querying data / chaining methods, using python.</p>
  <p>for instance the query below (taken from 'Learning Spark 2nd Edition'):</p>
  <pre><code>fire_ts_df.               
   select(&quot;CallType&quot;)
   .where(col(&quot;CallType&quot;).isNotNull())
   .groupBy(&quot;CallType&quot;)
   .count()
   .orderBy(&quot;count&quot;, ascending=False)
   .show(n=10, truncate=False)
  </code></pre>
  <p>will execute just fine.</p>
  <p>What i don't understand though, is that if i had written the code like: (moved the call to 'count()' higher)</p>
  <pre><code>fire_ts_df.               
   select(&quot;CallType&quot;)
   .count()
   .where(col(&quot;CallType&quot;).isNotNull())
   .groupBy(&quot;CallType&quot;)
   .orderBy(&quot;count&quot;, ascending=False)
   .show(n=10, truncate=False)
  </code></pre>
  <p>this wouldn't work.
  The problem is that i don't want to memorize the order, but i want to understand it. I feel it has something to do with proper method chaining in Python / Pyspark but I am not sure how to justify it. In other words, in a case like this, where multiple methods should be invoked and chained using (.), what is the right order and is there any specific rule to follow?</p>
  <p>Thanks a lot in advance</p>