Issue
There is a dataframe df with 2 columns col1 and col2. Both columns have randomly spread 0s and 1s. More zeros than ones. If col1 has a 1 on an index, program should be able to look for next first 1 in col2 and get the difference of indices of both rows.
Everytime this distribution is different also the sequence length.
Solution
Try with idxmax
id1 = df.col1.idxmax()
id2 = df.loc[id1:,'col2'].idxmax()
id2-id1
2
id2
4
id1
2
Answered By - BENY
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.