Home > Blockchain >  How to change a PANDAS cell based on another cell
How to change a PANDAS cell based on another cell

Time:07-30

ramirez_stabilized = andrew_ramirez[andrew_ramirez['Datacenter'].isin(['ATL2','ACT1'])]['payout']* .75
andrew_ramirez['payout'] = ramirez_stabilized

ramirez_regular = andrew_ramirez[andrew_ramirez['Datacenter'].isin(['ATL1', 'ATL3', 'BOS1'])]['payout']* .5
andrew_ramirez['payout'] = ramirez_regular

I am trying to multiply specific columns within 'payout' based on the corresponding column 'datacenter' within its specific row. The problem is that every time that I do this the ramirez_stabilized gets written over and replaced with the second one. Is there an efficient solution to this?

CodePudding user response:

You can use .loc and avoid the SettingWithCopyWarning warning:

andrew_ramirez.loc[andrew_ramirez['Datacenter'].isin(['ATL2','ACT1']), 'payout'] *= .75
andrew_ramirez.loc[andrew_ramirez['Datacenter'].isin(['ATL1', 'ATL3', 'BOS1']), 'payout'] *= .5
  • Related