title: Using Flask as an API to filter a dictionary
body: <p>I have converted a dataframe to a dictionary so I can implement an API through flask. I'm struggling to append the column name to every index in the dictionary and therefore cannot run the code:</p>
  <pre><code>@app.route('/api/v1/resources/names', methods=['GET'])
  def api_name():
      if 'name' in request.args:
          name = str(request.args['name'])
      else:
          return &quot;Error: No name was provided, Please specify a first and last name&quot;
      results = []
  
      for index['Name] in main_data:
          if (index == name):
              results.append(index)
      results = str(results)
      return jsonify(results)
  </code></pre>
  <p>And when I attempt to call the API</p>
  <pre><code>http://127.0.0.1:5000/api/v1/resources/names?name=John%20Doe
  TypeError: string indices must be integers
  </code></pre>
  <p>I figured that is due to my dictionary not having any column headers, I wish to convert the dictionary from</p>
  <pre><code>{
    &quot;John Doe&quot;: {
      &quot;2020-09-01&quot;: &quot;4:00PM&quot;, 
      &quot;2020-09-03&quot;: &quot;8:00AM&quot;, 
      &quot;2020-09-04&quot;: &quot;2:00PM&quot;, 
      &quot;2020-09-14&quot;: &quot;8:00AM&quot;, 
      &quot;2020-09-16&quot;: &quot;6:00PM&quot;, 
      &quot;2020-09-22&quot;: &quot;5:00PM&quot;, 
      &quot;2020-09-23&quot;: &quot;2:00PM&quot;, 
      &quot;2020-09-25&quot;: &quot;1:00PM&quot;, 
      &quot;2020-09-30&quot;: &quot;5:00PM&quot;, 
      &quot;2020-10-01&quot;: &quot;8:00PM&quot;, 
      &quot;2020-10-05&quot;: &quot;5:00PM&quot;, 
      &quot;2020-10-08&quot;: &quot;1:00PM&quot;, 
      &quot;2020-10-09&quot;: &quot;5:00PM&quot;, 
      &quot;2020-10-10&quot;: &quot;4:00PM&quot;, 
      &quot;2020-10-12&quot;: &quot;5:00PM&quot;, 
      &quot;2020-10-14&quot;: &quot;7:00PM&quot;
    }, 
    &quot;Firstname Lastname&quot;: {
      &quot;2020-08-20&quot;: &quot;11:00AM&quot;, 
      &quot;2020-08-21&quot;: &quot;10:00AM&quot;, 
      &quot;2020-08-22&quot;: &quot;10:00AM&quot;, 
      &quot;2020-08-23&quot;: &quot;11:00AM&quot;, 
      &quot;2020-08-24&quot;: &quot;10:00AM&quot;, 
      &quot;2020-08-25&quot;: &quot;11:00AM&quot;, 
      &quot;2020-08-26&quot;: &quot;2:00PM&quot;, 
      &quot;2020-08-27&quot;: &quot;4:00PM&quot;, 
      &quot;2020-08-28&quot;: &quot;2:00PM&quot;, 
      &quot;2020-08-29&quot;: &quot;1:00PM&quot;
    }
  }
  </code></pre>
  <p>to:</p>
  <pre><code>{Name: &quot;John Doe&quot;: {Date: &quot;2020-09-01&quot;: Time:&quot;4:00PM&quot; }}
  </code></pre>
  <p>The code I used in pandas to initally convert the dataframe to a dictionary looks like this</p>
  <pre><code>def buildDictionary():
      main_data = pd.read_csv('output.csv', delimiter=&quot;,&quot;, encoding='cp1252')
      nameDictionary = (main_data.groupby('Name')
         .apply(lambda x: dict(zip(x['Date'],x['Time'])))
         .to_dict())
      return nameDictionary
  </code></pre>
  <p>Here is some of the csv data aswell</p>
  <pre><code>Name    Time    Date
  FName LName 12:00PM     10/5/20
  FName LName 12:00PM     10/5/20
  FName LName 12:00PM     10/5/20
  FName LName 12:00PM     10/5/20
  FName LName 12:00PM     10/5/20
  FName LName 12:00PM     10/5/20
  FName LName 12:00PM     10/5/20
  </code></pre>
  <p>I'd like for it to return</p>
  <pre><code>  &quot;John Doe&quot;: {
      &quot;2020-09-01&quot;: &quot;4:00PM&quot;, 
      &quot;2020-09-03&quot;: &quot;8:00AM&quot;, 
      &quot;2020-09-04&quot;: &quot;2:00PM&quot;, 
      &quot;2020-09-14&quot;: &quot;8:00AM&quot;, 
      &quot;2020-09-16&quot;: &quot;6:00PM&quot;, 
      &quot;2020-09-22&quot;: &quot;5:00PM&quot;, 
      &quot;2020-09-23&quot;: &quot;2:00PM&quot;, 
      &quot;2020-09-25&quot;: &quot;1:00PM&quot;, 
      &quot;2020-09-30&quot;: &quot;5:00PM&quot;, 
      &quot;2020-10-01&quot;: &quot;8:00PM&quot;, 
      &quot;2020-10-05&quot;: &quot;5:00PM&quot;, 
      &quot;2020-10-08&quot;: &quot;1:00PM&quot;, 
      &quot;2020-10-09&quot;: &quot;5:00PM&quot;, 
      &quot;2020-10-10&quot;: &quot;4:00PM&quot;, 
      &quot;2020-10-12&quot;: &quot;5:00PM&quot;, 
      &quot;2020-10-14&quot;: &quot;7:00PM&quot;
    } 
  </code></pre>
  <p>but in order to do that, i need to index every column in the dictionary.</p>