Performing a merge in Pandas on a column containing a Python `range` or list-like
Since it looks like ranges are pretty big, and you are working with integer vales, you can just compute the min, max:
columns = look_up.columnslook_up['minval'] = look_up['col3'].apply(min)look_up['maxval'] = look_up['col3'].apply(max) (sample.merge(look_up, on=['col1','col2'], how='left', suffixes=['','_']) .query('minval <= col3 <= maxval') [columns])
Output:
col1 col2 col3 col41 1b 2b 42 h2 1a 2b 3 c5 1a 2a 21 b6 1b 2a 7 e