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.
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))
I get the error:
KeyError: 0
I know that the for loop isn't correct; does anyone have a solution?