Which is the best way of creating multiples dictionaries from a pandas dataframe based on columns values?
My dataframe has this format:
evtnum pcode energy
1 1 a 20.0
2 1 a 30.0
3 1 b 29.0
4 1 a 34.0
5 2 c 20.0
6 2 a 15.0
7 3 a 3.0
8 3 b 2.0
9 3 c 25.0
10 4 h 28.0
11 5 a 43.6
12 5 c 20.3
evtnum takes values from 1 to 5000 and pcode are 25 different letters. I have a set with these letters:
pcode_set = [a,b,c,d,h,...]
So, I want to obtain evtnum dictionaries of lenght(pcode_set) each one, counting the ocurrencies of each letter in each event and the mean value of the energy of this letter in this event. Something like this:
dict_1 = {a : [timesthat"a"appears in evtnum1,
energy mean value of a in evtnum1],
b : [timesthat"b"appears in evtnum1,
energy mean value of b in evtnum1]
...
}
dict_2 = {a : [timesthat"a"appears in evtnum2,
energy mean value of a in evtnum2],
b : [timesthat"b"appears in evtnum2,
energy mean value of b in evtnum2]
...
}
...
dict_5000 = {a : [timesthat"a"appears in evtnum5000,
energy mean value of a in evtnum5000],
b : [timesthat"b"appears in evtnum5000,
energy mean value of b in evtnum5000]
...
}
Please dont answer me how to count the letter's ocurrencies or how to calculate the mean value, these were just examples. I only want to know How can I create a multiple number of dictionaries and fill them taking into account the columns values of the dataframe.