Compute co-occurrence matrix by counting values in cells

后端 未结 4 473
醉梦人生
醉梦人生 2021-01-01 21:07

I have a dataframe like this

df = pd.DataFrame({\'a\' : [1,1,0,0], \'b\': [0,1,1,0], \'c\': [0,0,1,1]})

I want to get

  a         


        
4条回答
  •  轮回少年
    2021-01-01 21:36

    You can do a multiplication using @ operator for numpy arrays.

    df = pd.DataFrame(df.values.T @ df.values, df.columns, df.columns)
    

提交回复
热议问题