I'm trying to determine if a number in 1 column (COL A) is within a range of 2 numbers found in a nested list in another column (COL B). COL B can have several nested lists of numbers.
This is being done in Python and pandas dataframes. I'm confident I can achieve this by using for loops but I'd like to utilize a vectorized solution. My attempts at using np.where
include some variation of this (I've only gone so far as to address situations where column B only has 1 embedded list of numbers. I'm guessing I could use an embedded np.where
statement in the False parameter...):
test_df['inRange'] = np.where(np.isin(test_df['COL A'],list(range(test_df['COL B'][0][0],test_df['COL B'][0][1]))), 'match', 'no match')
However, I keep getting an Index Error: list index out of range
I speculate I'm not using the correct syntax to refer to embedded lists from another column when using np.where
.
Any insight into how to achieve what I'm attempting is appreciated. Thank you!