title: How to populate dataframe from dictionary in loop
body: <p>I am trying to perform entity analysis on text and I want to put the results in a dataframe. Currently the results are not stored in a dictionary, nor in a Dataframe. The results are extracted with two functions.</p>
  
  <p>df:</p>
  
  <pre><code>ID    title    cur_working    pos_arg         neg_arg                             date
  132   leave    yes            good coffee     management, leadership and salary   13-04-2018
  145   love it  yes            nice colleagues long days                           14-04-2018
  </code></pre>
  
  <p>I have the following code:</p>
  
  <pre><code>result = entity_analysis(df, 'neg_arg', 'ID')
  
  #This code loops through the rows and calls the function entities_text()
  def entity_analysis(df, col, idcol):
      temp_dict = {}
      for index, row in df.iterrows():
          id = (row[idcol])
          x = (row[col])
          entities = entities_text(x, id)
          #temp_dict.append(entities)
      #final = pd.DataFrame(columns = ['id', 'name', 'type', 'salience'])
      return print(entities)
  
  def entities_text(text, id):
      """Detects entities in the text."""
      client = language.LanguageServiceClient()
      ent_df = {}
      if isinstance(text, six.binary_type):
          text = text.decode('utf-8')
  
      # Instantiates a plain text document.
      document = types.Document(
          content=text,
          type=enums.Document.Type.PLAIN_TEXT)
  
      # Detects entities in the document.
      entities = client.analyze_entities(document).entities
  
      # entity types from enums.Entity.Type
      entity_type = ('UNKNOWN', 'PERSON', 'LOCATION', 'ORGANIZATION',
                     'EVENT', 'WORK_OF_ART', 'CONSUMER_GOOD', 'OTHER')
  
      for entity in entities:
          ent_df[id] = ({
              'name': [entity.name],
              'type': [entity_type[entity.type]],
              'salience': [entity.salience]
          })
      return print(ent_df)
  </code></pre>
  
  <p>This code gives the following outcome:</p>
  
  <pre><code>{'132': {'name': ['management'], 'type': ['OTHER'], 'salience': [0.16079013049602509]}}
  {'132': {'name': ['leadership'], 'type': ['OTHER'], 'salience': [0.05074194446206093]}}
  {'132': {'name': ['salary'], 'type': ['OTHER'], 'salience': [0.27505040168762207]}}
  {'145': {'name': ['days'], 'type': ['OTHER'], 'salience': [0.004272154998034239]}}
  </code></pre>
  
  <p>I have created <code>temp_dict</code> and a <code>final</code> dataframe in the function <code>entity_analysis()</code>. <a href="https://stackoverflow.com/questions/28056171/how-to-build-and-fill-pandas-dataframe-from-for-loop">This thread</a> explained that appending to a dataframe in a loop is not efficient. <strong>I don't know how to populate the dataframe in an efficient way</strong>. <a href="https://stackoverflow.com/questions/30854728/python3-4-dataframe-from-dictionary">These</a> <a href="https://stackoverflow.com/questions/3294889/iterating-over-dictionaries-using-for-loops">threads</a> are related to my question but they explain how to populate a Dataframe from existing data. When I try to use <code>temp_dict.update(entities)</code> and return <code>temp_dict</code> I get an error:</p>
  
  <blockquote>
    <p>in entity_analysis
        temp_dict.update(entities)
    TypeError: 'NoneType' object is not iterable</p>
  </blockquote>
  
  <p>I want the output to be like this:</p>
  
  <pre><code>ID          name                  type                salience
  132         management            OTHER               0.16079013049602509 
  132         leadership            OTHER               0.05074194446206093 
  132         salary                OTHER               0.27505040168762207 
  145         days                  OTHER               0.004272154998034239 
  </code></pre>