Problem
"How to match a row value to a column name and take that intersecting value in pandas"
Context
We have a pandas df like this:
df = pd.DataFrame([{'name': 'john', 'john': 1, 'mac': 10}, {'name': 'mac', 'john': 2, 'mac': 20}], columns=["name", "john", "mac"])
Looking like this:
name | john | mac
john | 1 | 10
mac | 2 | 20
Desired output
name | john | mac | value
john | 1 | 10 | 1
mac | 2 | 20 | 20
In words, the column "value" should take the number from the corresponding column where name intersects.
So, if name == 'john', then take the value from column 'john'
So, if name == 'mac', then take the value from column 'mac'
Tried so far
Bunch of lambdas (none successful).
Specifications
Python: 3.5.2
Pandas: 0.18.1