I want to multiply column values by a specific scalar based on the name of the column:
- if column name = "Math", then all the values in 'Math" column should be multiply by 5;
- if column name = "Physique", values in that column should be multiply by 4;
- if column name = "Bio", values in that column should be multiplied by 3;
- all the remaining columns should be multiplied by 2
What I have:
This is what I should have :
listm = ['Math', 'Physique', 'Bio']
def note_coef(row):
for m in listm:
if 'Math' in listm:
result = df['Math']*5
return result
df2=df.apply(note_coef)
df2
Note I stopped with only 1 if to test my code but the outcome is not what I expected. I am quite new in programming and here as well.