How do I use the QuantityFormula column to iterate over the column headers. For example to find
- where count (from QuantityFormula) == count (from headers.
- Take the value of that row
- To produce a new column called Quantity, with that value.
- 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
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.