title: how loop through dataframe to find specific values from an array and append these rows to empty dataframe
body: <p>I have a data frame (called keys) containing names and other info; I made the names the indices. Now there is an array containing names, and I want to pass this array into a for loop that will loop through the keys dataframe and append the rows with the name from the for loop as the index to an empty dataframe; I then want the program to return this new dataframe that contains only the info from the keys dataframe of the names from the array.</p>
  
  <pre><code>keys = pd.read_excel(FILE, sep = 'delimiter', skiprows = 5, header = None, names = colnames1)
  keys.set_index('Name', inplace = True)
  array = ['Name1', 'Name2']
  result = pd.DataFrame()
  for i in range(len(array)):
      result = result.append(keys.set_index(i))
  </code></pre>
  
  <p>I get the error:</p>
  
  <blockquote>
    <p>KeyError: 0</p>
  </blockquote>
  
  <p>I know that the for loop isn't correct; does anyone have a solution?</p>