如何找到数据框中所有 permutation/combination 时间序列的分布?

How to find the spread for all the permutation/combination of the timeseries in a data-frame?

我是 python 的新手。刚刚创建了一个大约 10 个时间序列的数据框,我想找到所有时间序列的所有 permutation/combination 的分布。 例如:

Sn.No     Series A          Series B            Series C
1             10              17                  12
2             11              13                  15
3             13              15                  13

需要展开(a-b)、(b-c)和(a-c)。

这是你想要的吗?

In [38]: from itertools import combinations

In [40]: df
Out[40]:
   Sn.No  Series_A  Series_B  Series_C
0      1        10        17        12
1      2        11        13        15
2      3        13        15        13

In [41]: cols = df.filter(like='Series_').columns

In [42]: cols
Out[42]: Index(['Series_A', 'Series_B', 'Series_C'], dtype='object')

In [43]: for c in combinations(cols, 2):
   ....:         colname = '{}_{}'.format(c[0].lstrip('Series_'), c[1].lstrip('Series_'))
   ....:         df[colname] = df[c[0]] - df[c[1]]
   ....:

In [44]: df
Out[44]:
   Sn.No  Series_A  Series_B  Series_C  A_B  A_C  B_C
0      1        10        17        12   -7   -2    5
1      2        11        13        15   -2   -4   -2
2      3        13        15        13   -2    0    2