I have a dataframe, it\'s in one hot format:
dummy_data = {\'a\': [0,0,1,0],\'b\': [1,1,1,0], \'c\': [0,1,0,1],\'d\': [1,1,1,0]} data = pd.DataFrame(dummy_data)
You can have some fun with matrix math!
u = np.diag(np.ones(df.shape[1], dtype=bool)) df.T.dot(df) * (~u)
a b c d a 0 1 0 1 b 1 0 1 3 c 0 1 0 1 d 1 3 1 0