In my code, the user inputs a text file which is saved as the variable "emplaced_animals_data." This variable has four columns (Animal ID, X location, Y location, and Z location) and the number of rows varies depending on which text file is uploaded. I then have another list (listed_animals) which contains animals that we want to gather location data about from the emplaced_animals_data. So far, I have created a new variable for each item in the listed_animals list. I want to be able to compare each of these new variables to my emplaced_items_data Animal ID column and store their appropriate locations without having to explicitly call "Animal1, Animal2, etc." Here is the code I currently have and what is being outputted:
listed_animals = ['cat', 'dog', 'bear', 'camel', 'elephant']
Animal1_Xloc = []
Animal1_Yloc = []
Animal1_Zloc = []
for i, value in enumerate(listed_animals):
for j in range(0, len(emplaced_animals_data)):
exec ("Animal%s=value" % (i))
if Animal1 == emplaced_animals_data[j,0]: #don't want to explicitly have to call
Animal1_Xloc = np.append(Animal1_Xloc, emplaced_animals_data[j,1])
Animal1_Yloc = np.append(Animal1_Yloc, emplaced_animals_data[j,2])
Animal1_Zloc = np.append(Animal1_Zloc, emplaced_animals_data[j,3])
print(Animal1)
print('X locations:', Animal1_Xloc)
print('Y locations:', Animal1_Yloc)
print('Z locations:', Animal1_Zloc)
dog
X locations: ['1' '2' '3' '4' '1' '2' '3' '4' '1' '2' '3' '4' '1' '2' '3' '4' '1' '2'
'3' '4']
Y locations: ['3' '12' '10' '8' '3' '12' '10' '8' '3' '12' '10' '8' '3' '12' '10' '8'
'3' '12' '10' '8']
Z locations: ['9' '8' '1' '1' '9' '8' '1' '1' '9' '8' '1' '1' '9' '8' '1' '1' '9' '8'
'1' '1']
The data being used in the emplaced_animals_data list can be found here: emplaced_animals_data visual
My goal is to plot each animals' locations with a different symbol, but because the listed_animals list may not always have the same animals or the same number of animals in it I can't call each animal explicitly. So any ideas on how I could make this iterative?