找到某个字符串后,将每个字符串标记为true,Pandas

w46czmvw  于 2023-02-02  发布在  其他
关注(0)|答案(1)|浏览(142)
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'})

我有下面的序列对象。我想做的是Map它,并将“onboarding return-start origin”之后的每一个字符串都标记为true。有什么想法可以让我建立这个条件吗?
预期结果

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

hmae6n7t1#

使用Series.cummax,通过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

相关问题