Case 1: df
has only ones and zeros in col2 and integer indexes.
>>> df
col1 col2
0 a 0
1 b 1
2 c 1
3 d 0
4 c 1
5 d 0
You can use:
>>> df.loc[df['col2'].idxmax() + 1:, 'col2'] = 0
>>> df
col1 col2
0 a 0
1 b 1
2 c 0
3 d 0
4 c 0
5 d 0
Case2: df
can have all kinds of values in col2 and has integer indexes.
>>> df # demo dataframe
col1 col2
0 a 0
1 b 1
2 c 2
3 d 2
4 c 3
5 d 3
You can use:
>>> df.loc[(df['col2'] == 1).idxmax() + 1:, 'col2'] = 0
>>> df
col1 col2
0 a 0
1 b 1
2 c 0
3 d 0
4 c 0
5 d 0
Case 3: df
can have all kinds of values in col2 and has an arbitrary index.
>>> df
col1 col2
u a -1
v b 1
w c 2
x d 2
y c 3
z d 3
You can use:
>>> df['col2'].iloc[(df['col2'].values == 1).argmax() + 1:] = 0
>>> df
col1 col2
u a -1
v b 1
w c 0
x d 0
y c 0
z d 0