I'm new to using dictionaries and I've been looking how to do this but I cannot find the answer to this specific problem.
I have a 4-level nested dictionary and inside the last level I have the values (arrays) of interest. It looks like this:
import numpy as np
A = np.array([1,2,3])
B = np.array([4,5,6])
C = np.array([7,8,9])
D = np.array([10,11,12])
E = np.array([13,14,15])
d={('domestic','dog','collie','old'):A,
('domestic','dog','golden','old'):B,
('domestic','dog','golden','young'):C,
('domestic','cat','siamese','young'):D,
('stray','dog','golden','old'):E}
What I need to do is operate over all arrays that satisfy certain condition(s) on a specific level.
For instance, I need the averages of all the arrays that have the word 'dog' in its second level, no matter if it's domestic or stray, or if it's old or young, etc.
And what if I needed to satisfy several conditions at once? For instance, average over all dogs that are young.
Any help is appreciated!
Edit: The reason why I was not using Pandas is because my arrays have 2 dimensions, and I'm looking how to operate over every (x,y) for each "key conditions". I realize now with some answers/comments how my title question is not clear, and how the example I provided is not showing what I was really intending to do. I'm sorry for that, I should learn not to post after a long day of work.
In Pandas I've always used averages over all values, but since what I need to do here is get an array of averages according to some conditions, I thought this couldn't be done using Pandas, so after some research I thought the best idea was to start using dictionaries to store the data.
In my example, what I would need to obtain is an array (x0,y0,z0) of averages. For instance, if I want the average over all "dogs" & "golden", the result should be
[ (B[0]+C[0])/2, (B[1]+C[1])/2, (B[2]+C[2])/2 ]
Is this possible to achieve using Pandas?