title: How to extract values from API response
body: <pre><code>import pandas as pd
  import requests
  import json
  
  
  def getAPIreturn(para):
      url = &quot;http://localhost/search?name={}&quot;.format(para)
      try:
          return_json = json.loads(requests.get(url).text)
          response = return_json['data'] # get the first response string
          print (type(response))
      except:
          response = &quot;&quot; 
      return response
  
  data = pd.read_csv(&quot;input.csv&quot;) 
  data['return'] = data['para'].apply(getAPIreturn)
  
  data.to_csv(&quot;output.csv&quot;,index=False)
  </code></pre>
  <p>The above code will read a csv file and read the first column named <code>input</code> for calling the API as a parameter then get the <code>data</code> back and save into the second column named <code>return</code> and output a CSV file.</p>
  <p>What if I want to select multiple values from the response? For example, <code>score</code>, <code>count</code>, <code>status</code> and save it back into CSV?</p>
  <pre><code>{
      &quot;data&quot;: [
          {
              &quot;score&quot;: 1234
          },
          {
              &quot;count&quot;: 2
          },
          {
              &quot;id&quot;: &quot;1234&quot;,
              &quot;Section&quot;: &quot;abc&quot;,
              &quot;DisplayName&quot;: &quot;hihi&quot;,
              &quot;status&quot;: &quot;History&quot;
          }
      ]
  }
  
  </code></pre>
  <p>preferred result in the csv file:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>input</th>
  <th>score</th>
  <th>count</th>
  <th>status</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>para</td>
  <td>score1</td>
  <td>1</td>
  <td>History</td>
  </tr>
  <tr>
  <td>para2</td>
  <td>score2</td>
  <td>2</td>
  <td>History</td>
  </tr>
  </tbody>
  </table>
  </div>