I have two dataframes. My first dataframe has two columns, which I would like to use to create a condition and return a value from the second dataframe. df1 = (['a', 'a', 'b', 'c'], [0.4, 0.9, 0.1, 0.6]) df2 = (['a', 'a', 'b', 'b', 'c', 'c'], [0.2, 0.6, 0.3, 0.8, 0.1, 0.4], [500, 200, 900, 400, 250, 800]) For each row in df1, I would like to look up df2 by the two columns of data. The first condition is to match the letter in df1 with df2. The second condition is to lookup the first number row in df2 where the number is greater than df1. If no number is greater, take the first row in df2 that matches the letter. My target output is: df1 row[0] = 500 # 'a' matches 'a' & 0.4 is greater than 0.2 df1 row[1] = 200 # 'a' matches 'a' & 0.9 is greater than 0.6 df1 row[2] = 900 # 'b' matches 'b' & no row is greater than 0.1 so return first 'b' row df1 row[3] = 800 # 'c' matches 'c' & 0.6 is greater than 0.4 Continue reading...