title: PySpark - Sum a column in dataframe and return results as int
body: <p>I have a pyspark dataframe with a column of numbers. I need to sum that column and then have the result return as an int in a python variable. </p>
  
  <pre><code>df = spark.createDataFrame([("A", 20), ("B", 30), ("D", 80)],["Letter", "Number"])
  </code></pre>
  
  <p>I do the following to sum the column. </p>
  
  <pre><code>df.groupBy().sum()
  </code></pre>
  
  <p>But I get a dataframe back. </p>
  
  <pre><code>+-----------+
  |sum(Number)|
  +-----------+
  |        130|
  +-----------+
  </code></pre>
  
  <p>I would 130 returned as an int stored in a variable to be used else where in the program. </p>
  
  <pre><code>result = 130
  </code></pre>