I have the following data frame:
timestamp col_A col_B col_C
0 2016-02-15 00:00:00 2.0 NaN NaN
1 2016-02-15 00:01:00 1.0 NaN NaN
2 2016-02-15 00:02:00 4.0 2.0 NaN
3 2016-02-15 00:03:00 2.0 2.0 NaN
4 2016-02-15 00:04:00 7.0 4.1 1.0
5 2016-02-15 00:05:00 2.0 5.0 2.0
6 2016-02-15 00:06:00 2.4 2.0 7.5
7 2016-02-15 00:07:00 2.0 6.3 1.2
8 2016-02-15 00:08:00 2.5 7.0 NaN
I want to find the cumulated sum of non-NaN records at each timestamp for each column. That is, the expected output data frame should be:
timestamp col_A col_B col_C
0 2016-02-15 00:00:00 1 NaN NaN
1 2016-02-15 00:01:00 2 NaN NaN
2 2016-02-15 00:02:00 3 1 NaN
3 2016-02-15 00:03:00 4 2 NaN
4 2016-02-15 00:04:00 5 3 1
5 2016-02-15 00:05:00 6 4 2
6 2016-02-15 00:06:00 7 5 3
7 2016-02-15 00:07:00 8 6 4
8 2016-02-15 00:08:00 9 7 NaN
I am looping over the data frame and find the cumsum record by record. However, I am wondering is there a more elegant to do this? Thanks!