import pandas as pd
from io import StringIO
import itertools as iter
matrix = pd.read_csv(StringIO(
    """ID,A1,A2,A3,B1,B2,B3
Ku8QhfS0n_hIOABXuE,6.343,6.304,6.410,6.287,6.403,6.279
fqPEquJRRlSVSfL.8A,6.752,6.681,6.680,6.677,6.525,6.739
ckiehnugOno9d7vf1Q,6.297,6.248,6.524,6.382,6.316,6.453
x57Vw5B5Fbt5JUnQkI,6.268,6.451,6.379,6.371,6.458,6.333"""
    )).set_index('ID')
print('Original DataFrame:')
print(matrix)
print() 
comparison_df = pd.DataFrame(index=matrix.index)
for a, b in iter.combinations(matrix.columns, 2):
    comparison_df['{}_{}'.format(a, b)] = matrix[a] - matrix[b]
print('Combination DataFrame:')
print(comparison_df)
Вычисление вычитания пар столбцов в pandas DataFrame