How to change a PANDAS cell based on another cell

Question:

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?

Asked By: mcccc

||

Answers:

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
Answered By: Corralien
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.