I have a dataset like this:
Sample Dataframe
import pandas as pd
df = pd.DataFrame({
'names': ['A','B','C','D','E','F','G','H','I','J','K','L'],
'col1': [0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0],
'col2': [0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0]})
I'd like to replace some of the 0's in col1 and col2 with 1's, but not replace the 0's if three or more 0's are consecutive in the same column. How can this be done with pandas?
Original Dataset:
names col1 col2
A 0 0
B 1 0
C 0 0
D 1 0
E 1 1
F 1 0
G 0 1
H 0 0
I 0 1
J 1 0
K 0 0
L 0 0
Desired Dataset:
names col1 col2
A 1 0
B 1 0
C 1 0
D 1 0
E 1 1
F 1 1
G 0 1
H 0 1
I 0 1
J 1 0
K 1 0
L 1 0