I am trying to append a column to my DataFrame that is based on the values that are referenced by indicated column names.
I have the following DataFrame:
Area 1 2 3 4 Select
-----------------------------------------------------------
0 22 54 33 46 23 4
1 45 36 54 32 14 1
2 67 34 29 11 14 3
3 54 35 19 22 45 2
4 21 27 39 43 22 3
The values under "Select" are referencing the values that are under the column number that "Select" shows. For example, for row 0, "Select" shows 4, which refers to the value under column "4" in row 0, which is 23. And then for row 1, "Select" shows 1, which refers to the value under column "1" in row 1, which is 36.
I want to append a new column to my DataFrame that has the values that "Select" is referencing.
And so I need to take my DataFrame and create the following DataFrame:
Area 1 2 3 4 Select Value
----------------------------------------------------------------------
0 22 54 33 46 23 4 23
1 45 36 54 32 14 1 36
2 67 34 29 11 14 3 11
3 54 35 19 22 45 2 19
4 21 27 39 43 22 3 43
I am not sure how to pull the values from under the numbered columns referenced by the "Select" column, since the column headers are just titles and not actual values to be indexed. How might this be accomplished in python?