Я знаю, как это сделать в R. Но существует ли какая-либо функция в pandas, которая преобразует dataframe в матрицу совпадений nxn, содержащую подсчеты двух связанных друг с другом аспектов.
Например, матрица df:
import pandas as pd
df = pd.DataFrame({'TFD' : ['AA', 'SL', 'BB', 'D0', 'Dk', 'FF'],
'Snack' : ['1', '0', '1', '1', '0', '0'],
'Trans' : ['1', '1', '1', '0', '0', '1'],
'Dop' : ['1', '0', '1', '0', '1', '1']}).set_index('TFD')
print df
>>>
Dop Snack Trans
TFD
AA 1 1 1
SL 0 0 1
BB 1 1 1
D0 0 1 0
Dk 1 0 0
FF 1 0 1
[6 rows x 3 columns]
даст:
Dop Snack Trans
Dop 0 2 3
Snack 2 0 2
Trans 3 2 0
Так как матрица зеркалируется по диагонали, я думаю, что был бы способ оптимизации кода.