title: From MongoDB dictionary to Dataframe mapping
body: <p>In my <a href="https://stackoverflow.com/questions/59142639/pandas-dataframe-growing-in-rows-and-columns/59142775?noredirect=1#comment104512468_59142775">previous question</a> I transform a DF into a list of dicts to upload to MongoDB.</p>
  
  <p>Now I'm doing the opposite work. From a MongoDB query I can download a list of dicts containing the following info: </p>
  
  <pre><code>[
  {Info1: 3,
   City: BCN,
   Country: Spain},
  
  {Info2: 5.6,
   City: BCN,
   Country: Spain},
  
  {Info1: 4,
   City: Moscow,
   Country: Russia},
  
  {Info2: 7,
   City: Moscow,
   Country: Russia}
  ]
  </code></pre>
  
  <p>Now i want to create a table as follows:</p>
  
  <pre><code>City    Country   Info1  Info2
  BCN      Spain    3      5.6   
  Moscow   Russia   4      7   
  </code></pre>
  
  <p>The way I'm doing it right now is as follows:</p>
  
  <pre><code>  def generate_excel(ind_type):
       # first add columns
       columns = ["City", "Country"]
  
       # then  find all indictors filtered
       indicators = []
       for indicator in CUSTOMERS_COLLECTION.find().distinct("ID"):
           indicators.append(indicator)
  
       # then add the indicators in column
       columns = columns + indicators
  
       # First find all Ciudades
       cities = CUSTOMERS_COLLECTION.find()
  
        rows_list = []
       for ciudad in cities.distinct("City"):
          indicators = CUSTOMERS_COLLECTION.find({"City": ciudad})
          dict_ind = {}
          # then we create a dict of the indicators. It will be the row
          for indicator in indicators:
              dict_ind[indicator["ID"]] = indicator["Valor"]
              dict_ind["Country"] = indicator["Country"]
              dict_ind["City"] = indicator["City"]
  
       df_ = pd.DataFrame(rows_list, columns=columns)
       return df_
  </code></pre>
  
  <p>As in my previous question, this works but it seems not optimized at all. Is there any functionality from MongoDB or from DF that allows mapping the dictionary correctly?</p>
  
  <p>Thanks!!</p>