I have 2 pandas dataframes df_x and df_y and I want to update a ‘SCORE’ column that they both have in common. I want to update the score column with a score of 100 if the following conditions are met:
- Age <= 45 AND column Banned != 1 OR column chargeback !=1
My trial below did not work. Any inputs?
if df_x.AGE_DAYS <= 45 and (df_x.BANNED != 1 or df_x.CHARGEBACK != 1):
df_x['SCORE'] = 100
if df_y.AGE_DAYS <= 45 and (df_y.BANNED != 1 or df_y.CHARGEBACK != 1):
df_y['SCORE'] = 100
Outcome: Basically, the 'Score' column should update the existing value with a 100 or do nothing at all if the above described criteria are met.
To set up a sample testing enviornment:
import pandas as pd
df = pd.DataFrame([[1, 1, 0], [100, 0,0], [46, 1, 0]], columns=['AGE_DAYS', 'Banned', 'Chargeback'])
print(df)
Desired output: Updated score column added to show that score values outside the criteria specified not changed. Only values changed if they meet the criteria of this search!
AGE BANNED CHARGEBACK SCORE "UPDATED SCORE"
45 1 0 75 75
33 0 0 45 **100**
44 0 0 77 **100**
235 0 1 75 75
43 1 0 88 88
21 0 0 23 **100**
1 0 0 56 **100**
432 1 1 12 12