I have a dictionary (mydict) which its keys are dates (timestamp), and its items are data frames (they all in the same shape) with two columns index and values as follows:
mydict: {
"Timestamp('2019-01-04 06:05:32')" : {
1, 4
2,23
3,2
4,32
},
" Timestamp('2019-01-05 05:02:12')" : {
1, 6
2,3
3,20
4, 2
}
"Timestamp('2019-01-10 08:05:32')" : {
1, 7
2,33
3,5
4,21
},
" Timestamp('2019-01-11 04:02:12')" : {
1, 4
2,11
3,7
4,11
}
I would like to group the keys based on the dates which are in the same week of the year. Then take the average of the data frames. For example, the first and second keys are in the first week of the year, so they should group together, and the same for third and fourth keys. Thus, my desired dictionary should be like this:
mynew_dict:
"week1" : {
1, 5
2,13
3,11
4,17
},
"week2" : {
1, 5.5
2,22
3,6
4,16
}