lundi 18 avril 2016

Python condition aggregation

A
    block_id     const         t                   
    2         4.620981e-01  0.050000
    4         1.737035e+00  0.107291
    5         1.103824e+00  0.138629
    7         2.772589e-01  0.069315
    8         2.255064e+00  0.383144
    9         5.771610e-17  0.050000


B  
      block_id       number
        2              1.666667
        4              4.500000
        5              2.750000
        7              1.250000
        8              4.833333

I have two dataframes like the above and block_id is their common key. I would like to ask how could I change the value of A['const'] only if the respective row of A['t'] is > 0.01. And the new value of A['const'] would be the respective value in B['number']*0.6 which has same block_id.

Is np.where(A['t'] > 0.01, ......] applicable here?

Aucun commentaire:

Enregistrer un commentaire