I have the following script and sample data:
import numpy as np
import pandas as pd
# Generating dummy data for testing
ROWS=10
COLS=20
X = np.random.randint(2, size=(ROWS, COLS))
# Visualizing
df = pd.DataFrame(data=X)
bg='background-color: '
df.style.apply(lambda x: [bg+'red' if v>=1 else bg+'yellow' for v in x])
My problem is:
How do I count the adjacent points (i.e., points with the same values and no gaps), group them, and label them according to the counts using python.
Here’s the expected image for the input above:
I’ll appreciate any help that you can provide.