title: How to create a PySpark DataFrame from a Python loop
body: <p>I am looping through multiple webservices which works fine</p>
  
  <pre><code>customers= json.loads(GetCustomers())
  
  for o in customers["result"]:
    if o["customerId"] is not None:
      custRoles = GetCustomersRoles(o["customerId"])
      custRolesObj = json.loads(custRoles)
  
      if custRolesObj["result"] is not None:
        for l in custRolesObj["result"]:
          print str(l["custId"]) + ", " + str(o["salesAmount"])
  </code></pre>
  
  <p>This works, and my output from print is also correct. But, now I need to create  a DataFrame out of this. I read, we cannot "create a DataFrame with two columns and add row by row while looping".</p>
  
  <p>But how would I solve this?</p>
  
  <p><strong>Update</strong></p>
  
  <p>I hope this is the correct way to create a list?</p>
  
  <pre><code>customers= json.loads(GetCustomers())
  result = []
  
  for o in customers["result"]:
    if o["customerId"] is not None:
      custRoles = GetCustomersRoles(o["customerId"])
      custRolesObj = json.loads(custRoles)
  
      if custRolesObj["result"] is not None:
        for l in custRolesObj["result"]:
            result.append(make_opportunity(str(l["customerId"]), str(o["salesAmount"])))
  </code></pre>
  
  <p>When this is correct, how to create a Dataframe out of it?</p>