if statement - 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 2 dataframes above , block_id common key. ask how change value of a['const'] if respective row of a['t'] > 0.01. , new value of a['const'] respective value in b['number']*0.6 has same block_id.

is np.where(a['t'] > 0.01, ......] applicable here?

dfa = dfa.set_index('block_id') dfb = dfb.set_index('block_id') dfb.rename(columns={'number':'const'}, inplace=true) # maybe not needed dfa.loc[:, 'const'] = dfa.const.where(dfa.t<=0.01, dfb.const) 

note: 1. cond in should <=

  1. if block_id in dfa , not in dfb, dfa may got na

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -