![enter image description here](https://i.stack.imgur.com/Jr3z1.png)

How do I use the QuantityFormula column to iterate over the column headers. For example to find

1. where count (from QuantityFormula) == count (from headers.
2. Take the value of that row
3. To produce a new column called Quantity, with that value.
4. Do the same for all Count, Area, Volume

It needs to work if new rows are added too.

I found this code online, to start with looking to modify it or create a new piece of code to do what I need. How do I loop and compare Column to header (lookup\_array == lookup\_value) and store row value of that.

Note: the NaN columns (count, area, volume) could have values in them in future tables

```py
def xlookup(lookup_value, lookup_array, return_array, if_not_found:str = ''):
    match_value = return_array.loc[lookup_array == lookup_value]
    if match_value.empty:
        return f'"{lookup_value}" not found!' if if_not_found == '' else if_not_found

    else:
        return match_value.tolist()[0]

Merged['Quantity'] = Merged['QuantityFormula'].apply(xlookup, args = (Merged['NRM'], left['UoM']))

```

I have a XLOOKUP functionality but I need something slightly different.