Skip to content
Advertisement

Check for max value of iterative sum in pandas

I have a pandas dataframe with some data:

JavaScript

I’d like to sum them, one at a time, and at every summation check the totalt sum, an then extract the highest value achieved of the total sum.

So the first sum would be element 0, with a value of -0.000601, the send would be -0.000601 + 0.000001=-0.0006, and this would be higher than the first sum (in other words, just element 0), so that value would be the max value up to that point.

I suppose a for loop could do the job but I’d prefer to do something pythonic like measure.loc[0:4, 'measure'].max() but this just checks the max value of the totalt sum.

Advertisement

Answer

I believe you need a cumulative sum and then to locate the max.

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement