Moving average on json of seq of objects in pandas

Viewed 25

Having this sequence of jsons :

{'2022-06-01 07:01:37': [{'delta': 0.25,
   'correlations': {'1M': 0.6755430615977345,
    '1W': 0.6840358858613861,
    '1Y': 0.667219973675597
    }},
  {'delta': -0.25,
   'correlations': {'1M': 0.7194583596406535,
    '1W': 0.7115303735149712,
    '1Y': 0.7034160936711537
   }},
  ],
 '2022-06-01 11:01:37': [{'delta': 0.25,
   'correlations': {'1M': 0.6755430615977345,
    '1W': 0.6840358858613861,
    '1Y': 0.667219973675597
    }},
  {'delta': -0.25,
   'correlations': {'1M': 0.7194583596406535,
    '1W': 0.7115303735149712,
    '1Y': 0.7034160936711537
   }},
  ],
 '2022-06-01 15:01:37': [{'delta': 0.25,
   'correlations': {'1M': 0.6755430615977345,
    '1W': 0.6840358858613861,
    '1Y': 0.667219973675597
    }},
  {'delta': -0.25,
   'correlations': {'1M': 0.7194583596406535,
    '1W': 0.7115303735149712,
    '1Y': 0.7034160936711537
   }},
  ]
}

I would like to do a daily moving average, only data under correlations node should be affected. The result should look like

{'2022-06-01': [{'delta': 0.25,
   'correlations': {'1M': 0.6755430615977345,
    '1W': 0.6840358858613861,
    '1Y': 0.667219973675597
    }},
  {'delta': -0.25,
   'correlations': {'1M': 0.7194583596406535,
    '1W': 0.7115303735149712,
    '1Y': 0.7034160936711537
   }},
  ]
}

Here the challenge is to have the moving average by bucket, like delta 0.25 not being mixed with the ones from delta -0.25 for example. I'm looking for an elegant way to do it using pandas dataframe without having to iterate manually through the sequences.

0 Answers
Related