Reputation: 23
I have data that looks something like this:
example = pd.Series([0,0,0,2,2,0], index = [2000, 2001, 2002, 2003, 2004, 2005])
How do I find the index corresponding to the first time that a condition is true?
For example, I want to find the index corresponding to the first nonzero entry, which in the example data is 2003.
Upvotes: 2
Views: 398
Reputation: 323316
By using nonzero
example.index[example.nonzero()[0][0]]
Out[267]: 2003
Upvotes: 2