I have this Panda series of integers, for example, s = pd.Series([1, 2, 3, 1, 5, 10])
. I need to find the index of the element starting from which the cumulative sum is equal to or greater some number, for example, 10
. So, for this series since print(s.cumsum())
gives us
0 1
1 3
2 6
3 7
4 12
5 22
I need to get 4
, because here the cumulative sum is greater than 10
.
What's the best Python way to find that index?
Just adding the condition idxmax
after cumsum
(s.cumsum()>10).idxmax()