【问题标题】:How to find the spread for all the permutation/combination of the timeseries in a data-frame?如何找到数据框中时间序列的所有排列/组合的分布?
【发布时间】:2016-06-24 08:11:31
【问题描述】:

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

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)。

【问题讨论】:

    标签: python pandas dataframe combinations permutation


    【解决方案1】:

    这就是你想要的吗?

    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
    

    【讨论】:

      猜你喜欢
      • 2021-01-21
      • 1970-01-01
      • 1970-01-01
      • 2020-12-24
      • 1970-01-01
      • 1970-01-01
      • 2021-11-21
      • 2020-09-26
      • 2019-03-29
      相关资源
      最近更新 更多