I have this dataframe call quest:
0_score 1_score 2_score 3_score 4_score 5_score true_label
0 0.007512 0.264500 0.273147 0.218029 0.233726 0.003084 1
1 0.130695 0.289085 0.173402 0.144897 0.238129 0.023792 1
2 0.006896 0.130070 0.289822 0.210133 0.219567 0.143512 4
3 0.006819 0.178320 0.259109 0.041048 0.316587 0.198118 1
4 0.011121 0.058437 0.182823 0.317847 0.123521 0.306250 3
I want to create a new column, based on the value in column true_label. I can do this:
scores = ['0_score', '1_score', '2_score', '3_score', '4_score','5_score']
(quest.assign(true_label_score = lambda df_:df_[scores[1]]))
Which gives me this:
0_score 1_score 2_score 3_score 4_score 5_score true_label true_label_score
0 0.007512 0.264500 0.273147 0.218029 0.233726 0.003084 1 0.264500
1 0.130695 0.289085 0.173402 0.144897 0.238129 0.023792 1 0.289085
2 0.006896 0.130070 0.289822 0.210133 0.219567 0.143512 4 0.130070
3 0.006819 0.178320 0.259109 0.041048 0.316587 0.198118 1 0.178320
4 0.011121 0.058437 0.182823 0.317847 0.123521 0.306250 3 0.058437
How do I replace the [scores[1]] with something like score[quest.true_label] so that for each row it uses the value in the true_label column to give me the correct column from the list scores, so that the value in column true_label_score comes from the matching column? Index row 2 should be using the value from 4_scores column and index row 4 should use the value from 3_scores column as the values in true_label_score.