代码之家  ›  专栏  ›  技术社区  ›  neves

熊猫:复合法有什么用?

  •  0
  • neves  · 技术社区  · 7 年前

    我发现了熊猫 compound dataframe method documentation 但它确实很简洁。我试着在一个简单的数据帧上运行它,但不了解它的实用性。下面是我的例子:

    In [5]: df = pd.DataFrame(np.arange(6).reshape(3,2), columns=['a', 'b'])
    
    In [6]: df
    Out[6]: 
       a  b
    0  0  1
    1  2  3
    2  4  5
    
    In [7]: df.compound()
    Out[7]: 
    a    14
    b    47
    dtype: int32
    

    我应该用这个方法做什么?

    1 回复  |  直到 7 年前
        1
  •  4
  •   rafaelc    7 年前

    这更像是贷款计算——复利

    enter image description here

    df.compound()
    Out[143]: 
    a    14
    b    47
    dtype: int32
    

    所以对于列 a

    enter image description here