title: Saving result of DataFrame show() to string in pyspark
body: <p>I would like to capture the result of <em>show</em> in pyspark, similar to <a href="https://stackoverflow.com/questions/54124386/capturing-the-result-of-explain-in-pyspark">here</a> and <a href="https://stackoverflow.com/questions/48546963/saving-contents-of-df-show-as-a-string-in-spark-scala-app?noredirect=1&amp;lq=1">here</a>. I was not able to find a solution with pyspark, only scala.</p>
  
  <pre class="lang-python prettyprint-override"><code>df.show()
  #+----+-------+
  #| age|   name|
  #+----+-------+
  #|null|Michael|
  #|  30|   Andy|
  #|  19| Justin|
  #+----+-------+
  </code></pre>
  
  <p>The ultimate purpose is to capture this as string inside my <code>logger.info</code>
  I tried <code>logger.info(df.show())</code> which will only display on console.</p>