熊猫层次结构数据框中与方差相关的条件

时间:2020-07-23 15:09:28

标签: python pandas dataframe

我有以下数据框:

    df
    Col1    Col2    Col3    Val1
    A       C       E       50
    A       C       F       30
    A       D       E       15
    A       D       F       5
    B       C       E       35
    B       C       F       13
    B       D       E       13
    B       D       F       43

我具有以下条件适用于上述数据框:以下是预期的输出:

    df2         : For Col1=A, calculate 90% of Val1 and show which contribute to 90% of Val1 from Col2
    Col1    Col2    Col3    Val1
    A       C       E       50
    A       C       F       30
    A       D       E       15
    
        
    df3         : Out of the Col2 values from step 1, calculate 75% of Val1 and show which contribute to 75% of that value from Col3
    Col1    Col2    Col3    Val1
    A       C       E       50
    A       C       F       30
    

    df3         :Out of the Col3 values from step 2, calculate 45% of Val1 and show which contribute to 45% of that value from Col4 
    Col1    Col2    Col3    Val1
    A       C       E       50

是否可以这样做?我无法确定实现该逻辑wrt数据帧的方法。

0 个答案:

没有答案