'How to swap signal without iterrows or itertuples

I'm struglling with pandas, I'm trying to define the B col as true after A col return 1, then return false when A col return 1 again.

Any ideas how to make this happen without iterrows or itertuples?

  A B 
0 0 false
1 0 false
2 1 true
3 0 true
4 0 true
5 1 true
6 0 false
7 0 false


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source