Below is the reproducible code
colo = ['red', 'red', 'red','cross','cross','red', 'red', 'red','cross','cross','cross',
'cross','cross', 'red', 'red','cross', 'red','cross','cross']
dt = pd.DataFrame()
dt['seq']=[i for i in range(len(colo))]
dt['col'] = colo
Expected Output:
The column seq
and col
is been given & Expected_col
is required to be created.
Here's one way using
eq
+diff
+ne
+cumsum
to greate groups; then use boolean indexing to fill in values:Output: