Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

After certain string is found mark every after string as true,pandas

s = pd.Series({0: 'registration address-complement-insert-confirmation input',
 1: 'decision-tree first-interaction-validation options',
 2: 'decision-tree invalid-format-validation options',
 3: 'decision-tree first-interaction-validation options',
 4: 'registration address-complement-request view',
 5: 'onboarding return-start origin',
 6: 'registration address-complement-request origin',
 7: 'decision-tree identified-regex options',
 8: 'decision-tree first-interaction-validation options',
 9: 'decision-tree first-interaction-validation options'})

I have the following series object. What I want to do is to map it and mark every single string after ‘onboarding return-start origin’ as true. Any ideas on how I could build this condition?

Wanted result

s = pd.Series({0: False,
 1: False,
 2: False,
 3: False,
 4: False,
 5: True,
 6: True,
 7: True,
 8: True,
 9: True})

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use Series.cummax with test first matched value by Series.eq:

s = s.eq('onboarding return-start origin').cummax()
print (s)
0    False
1    False
2    False
3    False
4    False
5     True
6     True
7     True
8     True
9     True
dtype: bool
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading