for i in range(l):
    maski = mask[i]
for j in range(i + 1):
    results[i, j] = results[j, i] = (maski & mask[j]).sum()
results = DataFrame(results, index=df.columns, columns=df.columns)
Fast way to see common observation counts for Python Pandas correlation matrix entries