There is a dataframe consists of a column of numbers that only includes '0, 1, 2'. Among them, '1' and '2' appear alternately, and there will not be two '1' or two '2' consecutively.
My goal is to change all the values in this column between 1 and 2 (start with 1 and including 1 and 2) to a special value say '9'. Maybe I can do this by looping through the whole df, but I wonder if pandas has an easier way to do it?
df = pd.DataFrame({'a':[2, 0, 1, 2, 0, 1, 0, 0, 2, 0, 1, 0, 0, 2, 0, 1]})
>>> df
a desired
0 2 2
1 0 0
2 1 9
3 2 9
4 0 0
5 1 9
6 0 9
7 0 9
8 2 9
9 0 0
10 1 9
11 0 9
12 0 9
13 2 9
14 0 0
15 1 1