I have a data frame like this,
df1
col1 col2
1 A
2 A
3 A
4 B
5 A
6 A
7 B
8 A
9 A
10 A
11 C
12 C
13 A
14 A
15 C
16 A
17 C
In above data frame total number of B and C are always even. Now I want to fill all the values between two B and C with B and C.
So the final data frame should look like,
df1
col1 col2
1 A
2 A
3 A
4 B
5 B
6 B
7 B
8 A
9 A
10 A
11 C
12 C
13 A
14 A
15 C
16 C
17 C
I could do it using a for loop, but the execution time will be huge, I am looking for some pandas shortcut / pythonic way to do it.