For the following dataframe:
import pandas as pd
df=pd.DataFrame({'list_A':[3,3,3,3,3,\
2,2,2,2,2,2,2,4,4,4,4,4,4,4,4,4,4,4,4]})
How can 'list_A' be manipulated to give 'list_B'?
Desired output:
| list_A | list_B | |
|---|---|---|
| 0 | 3 | 1 |
| 1 | 3 | 1 |
| 2 | 3 | 1 |
| 3 | 3 | 0 |
| 4 | 2 | 1 |
| 5 | 2 | 1 |
| 6 | 2 | 0 |
| 7 | 2 | 0 |
| 8 | 4 | 1 |
| 9 | 4 | 1 |
| 10 | 4 | 1 |
| 11 | 4 | 1 |
| 12 | 4 | 0 |
| 13 | 4 | 0 |
| 14 | 4 | 0 |
| 15 | 4 | 0 |
| 16 | 4 | 0 |
As you can see, if List_A has the number 3 - then the first 3 values of List_B are '1' and then the value of List_B changes to '0', until List_A changes value again.