I'm having a bit of trouble with my pandas data frame. I would like to compare measurements with the previous month's measurements. For this I need an extra column with the standard deviation and the average of the previous month.
I have the following table:
Time Value 1 Value 2 Value 3 Value 4
0 2020-04-01 03:42:51.531 9.189975 6.475000 3.962500 6.100006
1 2020-04-06 05:42:39.778 8.799253 7.300000 3.775000 6.119995
2 2020-04-06 06:45:55.211 8.824507 7.250000 3.600000 6.100006
3 2020-04-06 18:53:15.861 8.132523 6.312500 3.275000 6.100006
4 2020-04-07 05:39:54.373 8.772517 6.887500 3.962500 6.100006
... ... ... ... ... ...
17271 2021-03-31 22:12:32.374 9.012240 7.375000 3.750000 6.179993
17272 2021-03-31 22:43:51.906 9.038265 7.225000 3.800000 6.200012
17273 2021-03-31 23:12:27.061 9.091208 7.137500 3.887500 6.179993
17274 2021-03-31 23:44:14.439 9.109208 7.287500 3.962500 6.199997
17275 2021-04-01 00:00:00.000 9.111931 7.274812 3.973665 6.198373
For each of the four measurements per time step, I want an additional column (so a total of 8 extra columns) with the mean and standard deviation of the previous month. So for example, for each Value 1 measurement in January 2021, I want the Value 1 mean and standard deviation of December 2020.
I've been working on this for several days, but I can't manage to write a working python code for it. I hope someone can help me out. Thanks in advance!